Created
May 28, 2021 17:10
-
-
Save smmcdonald/3be8343369d537329dca2525e5c29f66 to your computer and use it in GitHub Desktop.
Check app version strings
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
| 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) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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