How to use compare on a version number where theres less parts in one number in Objective-C?

前端 未结 9 620
感情败类
感情败类 2021-01-22 02:30

I\'ve found the following code at http://snipplr.com/view/2771

Which is pretty good, almost exactly what I was looking for, but if I use the values @\"1.4.5\", @

9条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 02:43

    Why don't use NSString compare:options:NSNumericSearch

    NSString *sysVer = [[UIDevice currentDevice] systemVersion];
    NSLog(@"%@,%d,%d,%d", sysVer, [sysVer compare:@"1.0" options: NSNumericSearch], [sysVer compare:@"6.0" options: NSNumericSearch],[sysVer compare:@"10.0" options: NSNumericSearch]);
    if ([sysVer compare:@"6.0" options: NSNumericSearch]>=NSOrderedSame) {
        NSLog(@"ios 6");
    }
    

提交回复
热议问题