Skip to content

Instantly share code, notes, and snippets.

@jakubpetrik
Last active April 4, 2018 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakubpetrik/b68eaf88f0e4504659bb72c38e430f39 to your computer and use it in GitHub Desktop.
Save jakubpetrik/b68eaf88f0e4504659bb72c38e430f39 to your computer and use it in GitHub Desktop.
iOS version available (target iOS devices lower than a specific OS)
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