iOS自定义版本号比较

**代码如下,写的还比较粗糙 **

 -(int)compareVersion1:(NSString *)version1 version2:(NSString *)version2{

if ([version1 isEqualToString:version2]) {
    return 0;
}

NSArray *version1Arr = [version1 componentsSeparatedByString:@"."];
NSArray *version2Arr = [version2 componentsSeparatedByString:@"."];

NSMutableArray *mu1Arr = [NSMutableArray arrayWithArray:version1Arr];
NSMutableArray *mu2Arr = [NSMutableArray arrayWithArray:version2Arr];

for (NSInteger i = mu1Arr.count; i<3; i++) {
    [mu1Arr addObject:@"0"];
}
for (NSInteger i = mu2Arr.count; i<3; i++) {
    [mu2Arr addObject:@"0"];
}

for (int i=0; iv2?1:-1;
    }
    
    
}
return 0;
}

你可能感兴趣的:(iOS自定义版本号比较)