Skip to content

Made some upgrades to NSOperatingSystemVersion #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions Foundation/NSProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct NSOperatingSystemVersion {
public var majorVersion: Int
public var minorVersion: Int
public var patchVersion: Int

public init() {
self.init(majorVersion: 0, minorVersion: 0, patchVersion: 0)
}
Expand All @@ -31,6 +32,21 @@ public struct NSOperatingSystemVersion {
}
}

extension NSOperatingSystemVersion : Comparable {}

public func ==(lhs: NSOperatingSystemVersion, rhs: NSOperatingSystemVersion) -> Bool {
let lhsTuple = (lhs.majorVersion, lhs.minorVersion, lhs.patchVersion)
let rhsTuple = (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)

return lhsTuple == rhsTuple
}

public func <(lhs: NSOperatingSystemVersion, rhs: NSOperatingSystemVersion) -> Bool {
let lhsTuple = (lhs.majorVersion, lhs.minorVersion, lhs.patchVersion)
let rhsTuple = (rhs.majorVersion, rhs.minorVersion, rhs.patchVersion)

return lhsTuple < rhsTuple
}


public class NSProcessInfo : NSObject {
Expand Down Expand Up @@ -123,26 +139,7 @@ public class NSProcessInfo : NSObject {
}

public func isOperatingSystemAtLeastVersion(version: NSOperatingSystemVersion) -> Bool {
let ourVersion = operatingSystemVersion
if ourVersion.majorVersion < version.majorVersion {
return false
}
if ourVersion.majorVersion > version.majorVersion {
return true
}
if ourVersion.minorVersion < version.minorVersion {
return false
}
if ourVersion.minorVersion > version.minorVersion {
return true
}
if ourVersion.patchVersion < version.patchVersion {
return false
}
if ourVersion.patchVersion > version.patchVersion {
return true
}
return true
return operatingSystemVersion >= version
}

public var systemUptime: NSTimeInterval {
Expand Down
5 changes: 5 additions & 0 deletions TestFoundation/TestNSProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestNSProcessInfo : XCTestCase {

let version = processInfo.operatingSystemVersion
XCTAssertNotNil(version.majorVersion != 0)

XCTAssertEqual(NSOperatingSystemVersion(), NSOperatingSystemVersion())
XCTAssertEqual(NSOperatingSystemVersion(majorVersion: 0, minorVersion: 0, patchVersion: 0), NSOperatingSystemVersion())
XCTAssertLessThan(NSOperatingSystemVersion(majorVersion: 0, minorVersion: 0, patchVersion: 1), NSOperatingSystemVersion(majorVersion: 0, minorVersion: 0, patchVersion: 2))
XCTAssertGreaterThan(NSOperatingSystemVersion(majorVersion: 0, minorVersion: 0, patchVersion: 2), NSOperatingSystemVersion(majorVersion: 0, minorVersion: 0, patchVersion: 1)) //Guards against false positives in LT test
}

func test_processName() {
Expand Down