I have two different app version Strings (i.e. "3.0.1" and "3.0.2").
How can compare these using Swift?
In Swift, you can check for string and character equality with the "equal to" operator ( == ) and "not equal to" operator ( != ).
To check if two strings are equal in Swift, use equal to operator == with the two strings as operands. The equal to operator returns true if both the strings are equal or false if the strings are not equal.
Ended up having to convert my Strings to NSStrings:
if storeVersion.compare(currentVersion, options: NSStringCompareOptions.NumericSearch) == NSComparisonResult.OrderedDescending { println("store version is newer") }
Swift 3
let currentVersion = "3.0.1" let storeVersion = "3.0.2" if storeVersion.compare(currentVersion, options: .numeric) == .orderedDescending { print("store version is newer") }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With