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
import UIKit | |
/* KeyPath extension for listable paths */ | |
protocol KeyPathListable { } | |
extension KeyPathListable { | |
var allChildrenCount: Int { | |
let mirror = Mirror(reflecting: self) | |
return mirror.children.count | |
} |
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
var item: DispatchWorkItem! | |
item = DispatchWorkItem { | |
sleep(2) | |
guard !item.isCancelled else { | |
print("Work has been cancelled") | |
return | |
} | |
print("Work has been done") | |
} |
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
// MARK: UIView | |
public extension UIView { | |
private static var someTagKey: UInt8 = 0 | |
var someTag: String? { | |
get { return objc_getAssociatedObject(self, &Self.someTagKey) as? String } | |
set { objc_setAssociatedObject(self, &Self.someTagKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) } | |
} | |
} |
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
let updates = Updates( | |
bundle: Bundle.main.bundleId, | |
version: Bundle.main.appVersion) | |
updates.check { (status: UpdatesStatus) in | |
print("App update status: \(status)") | |
} |
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
// MARK: Bundle | |
public extension Bundle { | |
var appVersion: String { | |
return self.info(for: "CFBundleShortVersionString", or: "0.0.0") | |
} | |
var bundleId: String { | |
return self.info(for: "CFBundleIdentifier") | |
} | |
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
// MARK: Updates | |
public class Updates: UpdatesProtocol { | |
enum StorageKeys: String { | |
case postponedVersion = "UpdatesPostponedVersion" | |
} | |
private let userDefaults = UserDefaults.standard | |
private let queue = DispatchQueue(label: "com.limbo.FormsUpdates", qos: .default) | |
private let bundleId: String | |
private let currentVersion: Version? |
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
// MARK: UpdatesStatus | |
public enum UpdatesStatus { | |
case newVersion(_ version: Version) | |
case noChanges | |
case postponed | |
case undefined | |
public var isAvailable: Bool { | |
switch self { | |
case .newVersion: return true |
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
// MARK: UpdatesProtocol | |
public protocol UpdatesProtocol { | |
func check(completion: @escaping ((UpdatesStatus) -> Void)) | |
func check(cancelToken: CancelToken?, completion: @escaping ((UpdatesStatus) -> Void)) | |
func reset() | |
func postpone() | |
} |
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
// MARK: String | |
public extension String { | |
var asVersion: Version? { | |
return Version(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
// MARK: Version | |
extension Version: Equatable, Comparable { | |
public func isEqual(_ version: Version?) -> Bool { | |
guard let version: String = version?.version else { return false } | |
return version.compare(self.version, options: String.CompareOptions.numeric) == .orderedSame | |
} | |
public func isGreater(_ version: Version?) -> Bool { | |
guard let version: String = version?.version else { return false } | |
return version.compare(self.version, options: String.CompareOptions.numeric) == .orderedAscending |
NewerOlder