Created
March 19, 2019 18:44
-
-
Save tatimagdalena/70319f03523ea107e76e196c9d460b1f to your computer and use it in GitHub Desktop.
Comparing two version strings in the format "n.n.n" to see if the first one is outdated
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
static func isOutdated(thisVersion: String, comparisonVersion: String) -> Bool { | |
let thisVersionComponents = thisVersion.components(separatedBy: ".") | |
let comparisonVersionComponents = comparisonVersion.components(separatedBy: ".") | |
let thisVersionNumbers: [Int] = thisVersionComponents.map { Int($0) ?? 0 } | |
let comparisonVersionNumbers: [Int] = comparisonVersionComponents.map { Int($0) ?? 0 } | |
for i in 0 ..< 3 { | |
if thisVersionNumbers[i] > comparisonVersionNumbers[i] { | |
return false | |
} | |
else if thisVersionNumbers[i] < comparisonVersionNumbers[i] { | |
print("Outdated version") | |
return true | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment