Last active
December 20, 2018 08:45
-
-
Save gamako/6c8d56490049be9f4fa8dec1626bcb06 to your computer and use it in GitHub Desktop.
swift version string compare
This file contains 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
import Foundation | |
ComparisonResult.orderedAscending.rawValue // -1 | |
ComparisonResult.orderedSame.rawValue // 0 | |
ComparisonResult.orderedDescending.rawValue // 1 | |
"1.0.0".compare("1.0.1", options: .numeric, range: nil, locale: nil).rawValue // -1 (orderedAscending) | |
"1.0.0".compare("1.0.0", options: .numeric, range: nil, locale: nil).rawValue // 0 (orderedSame) | |
"1.0.0".compare("0.9.9", options: .numeric, range: nil, locale: nil).rawValue // 1 (orderedDescending) | |
"1.0.0".compare("1.0.1", options: .numeric, range: nil, locale: nil).rawValue // -1 (orderedAscending) | |
"1.0.1".compare("1.0.1", options: .numeric, range: nil, locale: nil).rawValue // 0 (orderedSame) | |
"1.0.2".compare("1.0.1", options: .numeric, range: nil, locale: nil).rawValue // 1 (orderedDescending) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment