比较 Objective-C 中的版本号 [英] Compare version numbers in Objective-C
本文介绍了比较 Objective-C 中的版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个应用程序,用于接收带有项目和版本号的数据.数字的格式为1.0.1"或1.2.5".如何比较这些版本号?我认为它们必须先格式化为字符串,不是吗?我有哪些选项可以确定1.2.5"在1.0.1"之后?
I am writing an application that receives data with items and version numbers. The numbers are formatted like "1.0.1" or "1.2.5". How can I compare these version numbers? I think they have to be formatted as a string first, no? What options do I have to determine that "1.2.5" comes after "1.0.1"?
推荐答案
这是比较版本的最简单方法,记住1"<1.0"<1.0.0":
This is the simplest way to compare versions, keeping in mind that "1" < "1.0" < "1.0.0":
NSString* requiredVersion = @"1.2.0";
NSString* actualVersion = @"1.1.5";
if ([requiredVersion compare:actualVersion options:NSNumericSearch] == NSOrderedDescending) {
// actualVersion is lower than the requiredVersion
}
这篇关于比较 Objective-C 中的版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文