iOS 用NSSortDescriptor对数组排序

释放双眼,带上耳机,听听看~!

不知道猿友们有没有用过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]];

人已赞赏
iOS文章

iOS打包上传错误:non-public selectors setCenterPoints:, setCities:解决办法

2019-10-28 11:15:52

iOS文章

AFNetworking 3.0与服务端 自签名证书 https双向认证

2019-10-28 11:45:51

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