Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- @return 如果版本号相等返回0,第一个版本号高于第二个,返回1,否则返回 -1.
- */
- - (NSInteger)compareVersion:(NSString *)version1 andVersion:(NSString *)version2{
- NSInteger res = 0;
- NSArray *arry1 = [version1 componentsSeparatedByString:@"."];
- NSArray *arry2 = [version2 componentsSeparatedByString:@"."];
- NSInteger idx1 = 0;
- NSInteger idx2 = 0;
- while (res == 0 && (idx1 < arry1.count || idx2 < arry2.count)) {
- id num1 = idx1 < arry1.count ? arry1[idx1] : 0;
- id num2 = idx2 < arry2.count ? arry2[idx2] : 0;
- if ([num1 integerValue] > [num2 integerValue]) {
- res = 1;
- }else if ([num1 integerValue] < [num2 integerValue]) {
- res = -1;
- }
- idx1++;
- idx2++;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement