比较Swift中的两个版本字符串 [英] Compare two version strings in Swift

查看:1144
本文介绍了比较Swift中的两个版本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的应用版本字符串(即3.0.1和3.0.2)。

I have two different app version Strings (i.e. "3.0.1" and "3.0.2").

如何使用 Swift <比较这些/ em>?

How can compare these using Swift?

推荐答案

结束必须将我的字符串转换为NSStrings:

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")
}

这篇关于比较Swift中的两个版本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆