数组排序 iOS
来源:互联网 发布:阿里云视频点播 编辑:程序博客网 时间:2024/06/06 17:47
// 1。普通数组排序:
NSMutableArray *arr = [NSMutableArrayarrayWithObjects:@"2",@"6",@"4",@"1",nil];
NSArray *sortedArray = [arrsortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2){
if ([obj1intValue] > [obj2 intValue]){
returnNSOrderedDescending;
}
if ([obj1intValue] < [obj2 intValue]){
returnNSOrderedAscending;
}
returnNSOrderedSame;
}];
NSLog(@"排序后的数组:%@",sortedArray);
// 2.数组中有字典的排序:
NSMutableArray *myMutableArr = [[NSMutableArrayalloc] init];
NSDictionary *dicOne = [NSDictionarydictionaryWithObjectsAndKeys:@"1",@"price",@"4",@"number",nil];
NSDictionary *dicTWo = [NSDictionarydictionaryWithObjectsAndKeys:@"2",@"price",@"3",@"number",nil];
NSDictionary *dicThree = [NSDictionarydictionaryWithObjectsAndKeys:@"3",@"price",@"2",@"number",nil];
NSDictionary *dicFour = [NSDictionarydictionaryWithObjectsAndKeys:@"4",@"price",@"2",@"number",nil];
[myMutableArr addObject:dicOne];
[myMutableArr addObject:dicTWo];
[myMutableArr addObject:dicThree];
[myMutableArr addObject:dicFour];
NSArray *sortDescriptors = [NSArrayarrayWithObject:[NSSortDescriptorsortDescriptorWithKey:@"price"ascending:YES]];
[myMutableArr sortUsingDescriptors:sortDescriptors];
NSLog(@"排序后的数组%@",myMutableArr);
- ios 数组排序-高级排序
- iOS 中数组排序
- iOS 数组排序
- iOS:字典数组排序
- iOS数组排序方法
- ios中文数组排序
- iOS数组快速排序
- iOS数组排序
- ios数组排序
- IOS数组排序
- ios数组排序
- iOS数组排序
- iOS 数组排序
- IOS数组排序
- iOS 数组/对象排序
- iOS 数组排序
- iOS对象数组排序
- iOS数组排序
- 关于Python杂七杂八的小东西(搭建Pycharm+Anaconda、删除文档首行小程序、皮尔逊相关系数小程序)
- grafana 配合influxdb监控的Sql例子
- 【WebService学习过程记录(三)】XFire开发Web Service---HelloWord
- 进程地址空间
- matlab中神经网络工具箱函数汇总
- 数组排序 iOS
- 马尔可夫模型学习
- Java IO ByteArrayInputStream和ByteArrayOutputStream
- Codeforces Round #332 (Div. 2)C. Day at the Beach
- Oracle数据库的学习(一)
- java中的分布式应用(一)之分布式介绍
- Java实现快速排序(泛型)
- LeetCode 338. Counting Bits
- Ubuntu服务器的NVIDIA驱动自动更新所引起的问题及解决方法m