iOS排序

作者: 若风_412d | 来源:发表于2020-10-10 09:04 被阅读0次

根据对象元素排序:
https://www.jianshu.com/p/7e64790c6cbd

iOS开发之数组内数字字符串排序

NSMutableArray *priceArray = [NSMutableArray arrayWithObjects:@"0.2",@"5",@"44",@"67",@"98.5",@"1.55", nil];

[priceArray sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2)
     {
         if ([obj1 integerValue] < [obj2 integerValue]){
             return NSOrderedAscending;
         }else{
             return NSOrderedDescending;
         }
     }];

这里再次得到的priceArray即为升序排列的数组;
若果想要得到降序的调换一下return的位置即可。

相关文章

网友评论

    本文标题:iOS排序

    本文链接:https://www.haomeiwen.com/subject/gdjdpktx.html