iOS 用NSSortDescriptor对数组排序
2016-09-09 本文已影响270人
喵喵退后
不知道猿友们有没有用过NSSortDescriptor对数组进行过排序,最近刚学会的新技能跟大家分享!
[ {
"id_": "0058896ae8b74ffda628d52fc4c66e2c",
"yw_id_": "46c63e06353d47e1b0135c24025ef6b7",
"yw_type_": "xw",
"create_time_": "2016-07-11 14:42:20",
"org_id_": "f5b54a169ad14b508806e7fb9e73646b",
"msg_content_": "",
"status_": "1"
},
{
"id_": "012ecffc807a48ebba0f416865e3ca77",
"yw_id_": "cdc5c62363c94812af038d3ac29f2611",
"yw_type_": "xw",
"create_time_": "2016-07-22 12:31:10",
"org_id_": "f5b54a169ad14b508806e7fb9e73646b",
"msg_content_": "",
"status_": "1"
},......]
- 这组数据要求根据“ create_time_”升序降序
- 升序 dataArray代表上面的数组
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"create_time_" ascending:Yes];
[dataArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
- 降序
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"create_time_" ascending:NO];
[dataArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];