我需要比较代表版本的2个字符串,比如1.2.4和2.3.6.我想知道在swift中是否已经存在一些类似的实现.也许类似于systemInfo函数的东西UIDevice.如果没有,您认为这是执行此检查的好方法吗?
一个好方法是compare:带选项的方法.NumericSearch
let version1 = "1.2.4"
let version2 = "2.3.6"
let result = version1.compare(version2, options: .numeric)
switch result {
case .orderedSame : print("versions are equal")
case .orderedAscending : print("version1 is less than version2")
case .orderedDescending : print("version1 is greater than version2")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
826 次 |
| 最近记录: |