我有这样一个数组:
NSArray *arr = @[@{@"index" : @"3", @"key" : @"value"}, @{@"index" : @"4", @"key" : @"value"}, @{@"index" : @"1", @"key" : @"value"}, @{@"index" : @"2", @"key" : @"value"}];
要重新按照字典里的index值排序变成这样:
NSArray *arr = @[@{@"index" : @"1", @"key" : @"value"}, @{@"index" : @"2", @"key" : @"value"}, @{@"index" : @"3", @"key" : @"value"}, @{@"index" : @"4", @"key" : @"value"}];
我现在的做法是遍历数组然后排序的办法。有没有优雅一点的做法。。感觉这样好麻烦
Compare method
Either you implement a compare-method for your object:
NSSortDescriptor (better)
or usually even better: (The default sorting selector of NSSortDescriptor is compare:)
Blocks (shiny!)
There's also the possibility of sorting with a block since 10.6: