ios 开发 根据数组内字典指定key排序

来源:互联网 发布:淘宝裸机是什么意思 编辑:程序博客网 时间:2024/05/21 21:47

NSArray *sortArray = @[

                           @{

                               @"id" :@"001",

                               @"name" :@"yanghuixue",

                               @"create_time" :@"1001"

                               },

                           @{

                               @"id" :@"002",

                               @"name" :@"yanghuixue",

                               @"create_time" :@"1002"

                               },

                           @{

                               @"id" :@"003",

                               @"name" :@"yanghuixue",

                               @"create_time" :@"1003"

                               },


                           @{

                               @"id" :@"004",

                               @"name" :@"yanghuixue",

                               @"create_time" :@"1004"

                               }

                           ];


- (NSArray *)sortArray:(NSArray *)array

{

    NSArray *sortDesc = [NSArrayarrayWithObject:[NSSortDescriptorsortDescriptorWithKey:@"create_time"ascending:YES]];

    NSArray *sortedArr = [arraysortedArrayUsingDescriptors:sortDesc];

    return sortedArr;

}



0 0