Skip to content

Commit df47b8f

Browse files
committed
Implemented Comparable on, and added initializer to, NSOperatingSystemVersion
1 parent 338f4bf commit df47b8f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Foundation/NSProcessInfo.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ public struct NSOperatingSystemVersion {
3131
}
3232
}
3333

34+
extension NSOperatingSystemVersion : Comparable {
35+
public init(_ majorVersion: Int, _ minorVersion: Int, _ patchVersion: Int) {
36+
self.init(majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: patchVersion)
37+
}
38+
}
39+
40+
public func ==(lhs: NSOperatingSystemVersion, rhs: NSOperatingSystemVersion) -> Bool {
41+
let lhsTuple = (lhs.majorVersion, lhs.minorVersion, lhs.patchVersion)
42+
let rhsTuple = (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)
43+
44+
return lhsTuple == rhsTuple
45+
}
46+
47+
public func <(lhs: NSOperatingSystemVersion, rhs: NSOperatingSystemVersion) -> Bool {
48+
let lhsTuple = (lhs.majorVersion, lhs.minorVersion, lhs.patchVersion)
49+
let rhsTuple = (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)
50+
51+
return lhsTuple < rhsTuple
52+
}
3453

3554

3655
public class NSProcessInfo : NSObject {
@@ -123,26 +142,7 @@ public class NSProcessInfo : NSObject {
123142
}
124143

125144
public func isOperatingSystemAtLeastVersion(version: NSOperatingSystemVersion) -> Bool {
126-
let ourVersion = operatingSystemVersion
127-
if ourVersion.majorVersion < version.majorVersion {
128-
return false
129-
}
130-
if ourVersion.majorVersion > version.majorVersion {
131-
return true
132-
}
133-
if ourVersion.minorVersion < version.minorVersion {
134-
return false
135-
}
136-
if ourVersion.minorVersion > version.minorVersion {
137-
return true
138-
}
139-
if ourVersion.patchVersion < version.patchVersion {
140-
return false
141-
}
142-
if ourVersion.patchVersion > version.patchVersion {
143-
return true
144-
}
145-
return true
145+
return operatingSystemVersion >= version
146146
}
147147

148148
public var systemUptime: NSTimeInterval {

0 commit comments

Comments
 (0)