This file contains hidden or 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
| public extension Bool { | |
| var not: Bool { !self } | |
| } | |
| // zip | |
| public extension Optional { | |
| static func zip<B>( | |
| _ a: Wrapped?, | |
| _ b: B? |
This file contains hidden or 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
| private extension Array { | |
| func chunked(into size: Int) -> [[Element]] { | |
| stride(from: 0, to: count, by: size).map { | |
| Array(self[$0 ..< Swift.min($0 + size, count)]) | |
| } | |
| } | |
| static func += (lhs: inout Self, rhs: Self.Element) { | |
| lhs.append(rhs) | |
| } |
This file contains hidden or 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
| // MARK: Optional | |
| public extension Optional where Wrapped == String { | |
| var orEmpty: String { self ?? "" } | |
| var isNilOrEmpty: Bool { | |
| orEmpty.isEmpty | |
| } | |
| var isNotNilNorEmpty: Bool { |
This file contains hidden or 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
| private func filter(searchText: String, using keyPath: KeyPath<Object, String>) -> [Object] { | |
| originalList.filter { | |
| let value = $0[keyPath: keyPath] | |
| return value == searchText | |
| } | |
| } | |
| private func filter(searchText: String, using matcher: @escaping (Object, String) -> Bool) -> [Object] { | |
| originalList.filter { object in | |
| matcher(object, searchText) |
This file contains hidden or 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
| static func isOutdated(thisVersion: String, comparisonVersion: String) -> Bool { | |
| let thisVersionComponents = thisVersion.components(separatedBy: ".") | |
| let comparisonVersionComponents = comparisonVersion.components(separatedBy: ".") | |
| let thisVersionNumbers: [Int] = thisVersionComponents.map { Int($0) ?? 0 } | |
| let comparisonVersionNumbers: [Int] = comparisonVersionComponents.map { Int($0) ?? 0 } | |
| for i in 0 ..< 3 { | |
| if thisVersionNumbers[i] > comparisonVersionNumbers[i] { |
This file contains hidden or 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
| -------------- | |
| - Rx testing: | |
| -------------- | |
| https://github.com/ReactiveX/RxSwift/blob/master/Documentation/UnitTests.md | |
| http://rx-marin.com/post/rxswift-rxtests-unit-tests/ | |
| http://rx-marin.com/post/rxblocking-part1/ | |
| http://adamborek.com/rxtests-rxactionsheet/ |
This file contains hidden or 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
| let granularity = Calendar.Component.day | |
| let comparisonResult = Calendar.current.compare(firstDate, to: secondDate, toGranularity: granularity) | |
| // granularity: | |
| // .second | |
| // .minute | |
| // .hour | |
| // .day | |
| // .month | |
| // .year |
This file contains hidden or 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
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| self.view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:)))) | |
| } | |
| } |
This file contains hidden or 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
| import Foundation | |
| extension String { | |
| public var upperCasedFirstLetter: String { | |
| prefix(1).uppercased() + dropFirst() | |
| } | |
| public var lowerCasedFirstLetter: String { | |
| prefix(1).lowercased() + dropFirst() |
This file contains hidden or 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
| func convertToValidInt(amount: String) -> Int? | |
| if amount != "" { | |
| let badCharacters = CharacterSet.decimalDigits.inverted | |
| if amount.rangeOfCharacter(from: badCharacters) == nil { | |
| if let amount = Int(amount) { | |
| if amount > 0 { | |
| return amount | |
| } | |
| } | |
| } |
NewerOlder