iOS开发——根据数组中的字典中的某一元素排序
2017-01-20 16:48
405 查看
数组中的元素是字典,字典中的某一个元素,比如说姓名,现在需要按照姓名的首字母来排序,怎么搞?
做法很简单,在字典中加一个元素,保存姓名的首字母,然后用下面的方法排序。
- (void)sortWifiList {
NSArray *resultArray = [myDataArray sortedArrayUsingFunction:compare context:NULL];
[myDataArray removeAllObjects];
[myDataArray addObjectsFromArray:resultArray];
}
NSComparisonResult compare(NSDictionary *firstDict, NSDictionary *secondDict, void *context) {
if ([[firstDict objectForKey:@"SSIDSortKey"] intValue] < [[secondDict objectForKey:@"SSIDSortKey"] intValue])
return NSOrderedAscending;
else if ([[firstDict objectForKey:@"SSIDSortKey"] intValue] > [[secondDict objectForKey:@"SSIDSortKey"] intValue])
return NSOrderedDescending;
else
return NSOrderedSame;
}
做法很简单,在字典中加一个元素,保存姓名的首字母,然后用下面的方法排序。
- (void)sortWifiList {
NSArray *resultArray = [myDataArray sortedArrayUsingFunction:compare context:NULL];
[myDataArray removeAllObjects];
[myDataArray addObjectsFromArray:resultArray];
}
NSComparisonResult compare(NSDictionary *firstDict, NSDictionary *secondDict, void *context) {
if ([[firstDict objectForKey:@"SSIDSortKey"] intValue] < [[secondDict objectForKey:@"SSIDSortKey"] intValue])
return NSOrderedAscending;
else if ([[firstDict objectForKey:@"SSIDSortKey"] intValue] > [[secondDict objectForKey:@"SSIDSortKey"] intValue])
return NSOrderedDescending;
else
return NSOrderedSame;
}
相关文章推荐
- iOS上传图片方向不对处理
- iOS-获取视频的任意一帧
- Firebase 远程配置 iOS 教程
- iOS证书及ipa包重签名探究
- iOS 启动图尺寸大小
- iOS10自定义tabBar出错
- iOS 关于音乐锁屏控制音乐(锁屏信息设置)
- iOS动画案例(1) 仿qq账号信息里的一个动画
- IOS 字符串中去除特殊符号 stringByTrimmingCharactersInSet
- iOS TableView滚动到最底部
- Nagios 系统监控基本安装配置过程详解
- iOS 自定义返回按钮保留系统滑动返回功能
- 小说搜索阅读-技术支持
- iOS的3DES加密写法
- ios 应用闪退原因
- iOS 启动图载入设置
- iOS打包项目时未生成dsyms文件
- iOS--CLLocationManager 定位
- ios开发者今天第一天来报道
- iOS性能优化--部分