Skip to content

Commit

Permalink
Merge pull request #27 from AckeeCZ/new_stuff
Browse files Browse the repository at this point in the history
New stuff
  • Loading branch information
janmisar authored Jun 25, 2018
2 parents 9434889 + baccda9 commit 0997f60
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 108 deletions.
68 changes: 48 additions & 20 deletions ACKategories.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ extension Array: SafeRandomAccessCollection {
return indices ~= index ? self[index] : nil
}
}

extension Array where Element: Equatable {
/// Remove given object
public mutating func remove(object: Element) {
if let index = index(of: object) {
remove(at: index)
}
}
}
12 changes: 12 additions & 0 deletions ACKategories/BundleExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

extension Bundle {
/// Get receipt data
public var receiptData: Data? { return appStoreReceiptURL.flatMap { try? Data(contentsOf: $0) } }

/// Get `CFBundleShortVersionString`
public var version: String? { return infoDictionary?["CFBundleShortVersionString"] as? String }

/// Get `CFBundleVersion`
public var buildNumber: Int? { return (infoDictionary?["CFBundleVersion"] as? String).flatMap { Int($0) } }
}
13 changes: 13 additions & 0 deletions ACKategories/CollectionExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation

extension Optional where Wrapped: Collection {
/// Return `true` if `self` is empty or nil
public var isEmpty: Bool {
switch self {
case .none:
return true
case .some(let value):
return value.isEmpty
}
}
}
21 changes: 21 additions & 0 deletions ACKategories/DateExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

extension Date {
/// Seconds from date
public var second: Int { return Calendar.current.component(.second, from: self) }

/// Minutes from date
public var minute: Int { return Calendar.current.component(.minute, from: self) }

/// Hours from date in 24-hour format
public var hour: Int { return Calendar.current.component(.hour, from: self) }

/// Days from date
public var day: Int { return Calendar.current.component(.day, from: self) }

/// Months from date
public var month: Int { return Calendar.current.component(.month, from: self) }

/// Year from date
public var year: Int { return Calendar.current.component(.year, from: self) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extension Optional: OptionalProtocol {
}

extension Dictionary where Value: OptionalProtocol {

/// Removes nils from dictionary
public var nilsRemoved: [Key: Value.WrappedValue] {
return self.reduce([:]) { acc, element -> [Key: Value.WrappedValue] in
Expand Down Expand Up @@ -45,62 +44,9 @@ extension Dictionary where Value: OptionalProtocol {
}
}

extension Optional where Wrapped: Collection {
/// Return `true` if `self` is empty or nil
public var isEmpty: Bool {
switch self {
case .none:
return true
case .some(let value):
return value.isEmpty
}
}
}

extension NumberFormatter {
public func string(from number: Int) -> String? {
return string(from: NSNumber(value: number))
}

public func string(from double: Double) -> String? {
return string(from: NSNumber(value: double))
}
}

/// Merge two dictionaries, if `lhs` contains same key as `rhs` it will be overwritten by `rhs` value
public func +<Key, Value> (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] {
var result = lhs
for (k, v) in rhs { result.updateValue(v, forKey: k) }
return result
}

extension Array where Element: Equatable {
/// Remove given object
public mutating func remove(object: Element) {
if let index = index(of: object) {
remove(at: index)
}
}
}

extension Bundle {
/// Get receipt data
public var receiptData: Data? { return appStoreReceiptURL.flatMap { try? Data(contentsOf: $0) } }

/// Get `CFBundleShortVersionString`
public var version: String? { return infoDictionary?["CFBundleShortVersionString"] as? String }

/// Get `CFBundleVersion`
public var buildNumber: Int? { return (infoDictionary?["CFBundleVersion"] as? String).flatMap { Int($0) } }
}

extension TimeInterval {
/// One minute
public static var minute: TimeInterval { return TimeInterval(60) }

/// One hour
public static var hour: TimeInterval { return minute * 60 }

/// One day
public static var day: TimeInterval { return hour * 24 }
}
8 changes: 0 additions & 8 deletions ACKategories/NSAttributedStringExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// NSAttributedStringExtensions.swift
// ACKategories
//
// Created by Josef Dolezal on 04/02/2018.
// Copyright © 2018 Josef Dolezal. All rights reserved.
//

import Foundation

public extension NSAttributedString {
Expand Down
8 changes: 0 additions & 8 deletions ACKategories/NSMutableParagraphStyleExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// NSMutableParagraphStyleExtensions.swift
// ACKategories
//
// Created by Jakub Olejník on 13/04/2018.
// Copyright © 2018 Josef Dolezal. All rights reserved.
//

import UIKit

extension NSMutableParagraphStyle {
Expand Down
11 changes: 11 additions & 0 deletions ACKategories/NumberFormatterExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

extension NumberFormatter {
public func string(from number: Int) -> String? {
return string(from: NSNumber(value: number))
}

public func string(from double: Double) -> String? {
return string(from: NSNumber(value: double))
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions ACKategories/TimeIntervalExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

extension TimeInterval {
/// One minute
public static var minute: TimeInterval { return TimeInterval(60) }

/// One hour
public static var hour: TimeInterval { return minute * 60 }

/// One day
public static var day: TimeInterval { return hour * 24 }
}
10 changes: 0 additions & 10 deletions ACKategories/UIButton+FixedIntrinsicContentSize.swift

This file was deleted.

17 changes: 9 additions & 8 deletions ACKategories/UIButtonExtensions.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// UIButtonExtensions.swift
// ACKategories
//
// Created by Jakub Olejník on 06/02/2018.
// Copyright © 2018 Josef Dolezal. All rights reserved.
//

import UIKit

extension UIButton {
Expand All @@ -18,3 +10,12 @@ extension UIButton {
titleEdgeInsets = UIEdgeInsets(top: 0, left: -imageSize.width, bottom: -(totalHeight - titleSize.height), right: 0)
}
}

extension UIButton {
open override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
let width = size.width + titleEdgeInsets.left + titleEdgeInsets.right
let height = size.height + titleEdgeInsets.top + titleEdgeInsets.bottom
return CGSize(width: width, height: height)
}
}
File renamed without changes.
9 changes: 9 additions & 0 deletions ACKategories/UIStackViewExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import UIKit

@available(iOS 9.0, *)
extension UIStackView {
/// Remove all arranged subviews
public func removeAllArrangedSubviews() {
arrangedSubviews.forEach { removeArrangedSubview($0); $0.removeFromSuperview() }
}
}
64 changes: 64 additions & 0 deletions Tests/DateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// DateTests.swift
// ACKategories
//
// Created by Jakub Olejník on 13/06/2018.
// Copyright © 2018 Ackee, s.r.o. All rights reserved.
//

import XCTest
import ACKategories

final class DateTests: XCTestCase {

var date: Date!

override func setUp() {
super.setUp()

date = Date()
}

func testCorrectSecond() {
let df = DateFormatter()
df.dateFormat = "s"

XCTAssertEqual(Int(df.string(from: date)), date.second)
}

func testCorrectMinute() {
let df = DateFormatter()
df.dateFormat = "m"

XCTAssertEqual(Int(df.string(from: date)), date.minute)
}

func testCorrectHour() {
let df = DateFormatter()
df.dateFormat = "H"

XCTAssertEqual(Int(df.string(from: date)), date.hour)
}

func testCorrectDay() {
let df = DateFormatter()
df.dateFormat = "d"

XCTAssertEqual(Int(df.string(from: date)), date.day)
}

func testCorrectMonth() {
let df = DateFormatter()
df.dateFormat = "M"

XCTAssertEqual(Int(df.string(from: date)), date.month)
}

func testCorrectYear() {
let df = DateFormatter()
df.dateFormat = "YYYY"

XCTAssertEqual(Int(df.string(from: date)), date.year)
}
}

28 changes: 28 additions & 0 deletions Tests/UIStackViewTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// UIStackViewTests.swift
// ACKategories
//
// Created by Jakub Olejník on 13/06/2018.
// Copyright © 2018 Ackee, s.r.o. All rights reserved.
//

import XCTest
import ACKategories

final class UIStackViewTests: XCTestCase {

func testViewsAreRemoved() {
let views = (0..<10).map { _ in UIView() }
let stack = UIStackView(arrangedSubviews: views)

XCTAssertEqual(views.count, stack.arrangedSubviews.count)

views.forEach { XCTAssertEqual(stack, $0.superview) }

stack.removeAllArrangedSubviews()

XCTAssertEqual(0, stack.arrangedSubviews.count)
views.forEach { XCTAssertNil($0.superview) }
}

}

0 comments on commit 0997f60

Please sign in to comment.