Reputation: 621
I have a problem with sorting... I need to sort NSArray
containing NSDictionaries
. As an order key I have to use element from the NSDictionary
.
I was reading a little about sorting NSArray
but it is not clear to me.
Could you try help me?
Upvotes: 1
Views: 373
Reputation: 299265
Use an NSSortDescriptor
and a keypath. Assuming the key for the dictionary is key
:
NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"key" ascending:YES];
NSArray *sorted = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sd]];
Upvotes: 1