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; i<mu1Arr.count; i++) {
NSInteger v1 = [mu1Arr[i] integerValue];
NSInteger v2 = [mu2Arr[i] integerValue];
if (v1!=v2) {
return v1>v2?1:-1;
}
}
return 0;
}

人已赞赏
iOS文章

Linux下ndk编译移植FFmpeg到Android平台

2020-1-18 12:57:33

iOS文章

iOS开发UILabel展开和收起(YYLabel)

2020-1-18 14:25:14

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索