How to sort an array which contains Dictionaries?

前端 未结 5 405
Happy的楠姐
Happy的楠姐 2020-12-30 20:05

I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values?

5条回答
  •  没有蜡笔的小新
    2020-12-30 20:43

    The other way to achieve this would be using sortedArrayUsingComparator: method

    NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        return [[obj1 valueForKey:@"value"] compare:[obj2 valueForKey:@"value"]];
    }];
    

提交回复
热议问题