Skip to content

Instantly share code, notes, and snippets.

@smmcdonald
Created May 28, 2021 17:10
Show Gist options
  • Select an option

  • Save smmcdonald/3be8343369d537329dca2525e5c29f66 to your computer and use it in GitHub Desktop.

Select an option

Save smmcdonald/3be8343369d537329dca2525e5c29f66 to your computer and use it in GitHub Desktop.
Check app version strings
func checkAppVersion(requiredVersion: String) {
guard let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String else { return }
let currentVersionNumbers = version.components(separatedBy: ".")
let requiredVersionNumbers = requiredVersion.components(separatedBy: ".")
var count = 0
for number in currentVersionNumbers {
if count < requiredVersionNumbers.count {
if compareNumeric(number, requiredVersionNumbers[count]) == .orderedAscending {
//TODO: self.forceUpdate() here
}
}
count += 1
}
}
func compareNumeric(_ currentVersion: String, _ requiredVersion: String) -> ComparisonResult {
return currentVersion.compare(requiredVersion, options: .numeric)
}
@smmcdonald
Copy link
Author

While this was designed for app versioning of the format "x.x.x", this should work for most standardized app versioning conventions including:
x.xx
x.x.xreleaseCandidatex.x
yyyy.mm.dd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment