Skip to content

Instantly share code, notes, and snippets.

@enomoto
Created May 17, 2018 01:05
Show Gist options
  • Save enomoto/d600b87563d2c1f897959f856b44646c to your computer and use it in GitHub Desktop.
Save enomoto/d600b87563d2c1f897959f856b44646c to your computer and use it in GitHub Desktop.
samples of NSComparisonResult
import Foundation
// https://developer.apple.com/documentation/foundation/nscomparisonresult
let currentVersion = "0.0.2"
let latestVersion1 = "0.0.3"
let latestVersion2 = "0.0.21"
let latestVersion3 = "0.1.0"
let latestVersion4 = "1.0.0"
let latestVersion5 = "0.0.2"
// tests
(currentVersion.compare(latestVersion1) == .orderedAscending) == true
(latestVersion1.compare(myVersion) == .orderedAscending) == false
(myVersion.compare(latestVersion2) == .orderedAscending) == true
(myVersion.compare(latestVersion3) == .orderedAscending) == true
(myVersion.compare(latestVersion4) == .orderedAscending) == true
(myVersion.compare(latestVersion5) == .orderedAscending) == false
(myVersion.compare(latestVersion5) == .orderedDescending) == false
(myVersion.compare(latestVersion5) == .orderedSame) == true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment