Last active
April 4, 2018 08:06
-
-
Save jakubpetrik/b68eaf88f0e4504659bb72c38e430f39 to your computer and use it in GitHub Desktop.
iOS version available (target iOS devices lower than a specific OS)
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
typealias iOS = OperatingSystemVersion | |
extension OperatingSystemVersion { | |
init(_ major: Int) { | |
self.init(majorVersion: major, minorVersion: 0, patchVersion: 0) | |
} | |
} | |
extension OperatingSystemVersion: Comparable { | |
public static func < (lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool { | |
guard lhs.majorVersion == rhs.majorVersion else { | |
return lhs.majorVersion < rhs.majorVersion | |
} | |
guard lhs.minorVersion == rhs.minorVersion else { | |
return lhs.minorVersion < rhs.minorVersion | |
} | |
return lhs.patchVersion < rhs.patchVersion | |
} | |
public static func == (lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool { | |
return lhs.majorVersion == rhs.majorVersion && | |
lhs.minorVersion == rhs.minorVersion && | |
lhs.patchVersion == rhs.patchVersion | |
} | |
} | |
func available(_ version: OperatingSystemVersion, _ compare: (OperatingSystemVersion, OperatingSystemVersion) -> Bool) -> Bool { | |
return compare(ProcessInfo.processInfo.operatingSystemVersion, version) | |
} | |
// usage: | |
if available(iOS(11), <) { | |
print("not ios 11") | |
} else { | |
print("ios 11") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment