-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from AckeeCZ/new_stuff
New stuff
- Loading branch information
Showing
17 changed files
with
236 additions
and
108 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) } | ||
} | ||
|
||
} |