Article From:https://www.cnblogs.com/liuyongfa/p/9967919.html

Reference: https://www.jianshu.com/p/1dd7745f5ee4

NSStringCompareOptionsHere’s an NSNumeric Search

 /* Added in 10.2; Numbers within strings are compared using numeric value, that is, Foo2.txt < Foo7.txt < Foo25.txt; only applies to compare methods, not find */

Object-C

    NSString *currentVersion = @"1.2.1";
    NSString *serverVersion = @"1.11.1";
    if ([currentVersion compare:serverVersion options:NSNumericSearch] == NSOrderedAscending) {
        NSLog(@"Need updating");
    }

Swift

        let currentVersion = "1.2.1"
        let serverVersion = "1.11.1"
        if currentVersion.compare(serverVersion, options: .numeric) == .orderedAscending {
            print("Need updating")
        }

 

Link of this Article: IOS App Version Number compare

Leave a Reply

Your email address will not be published. Required fields are marked *