How can I sort an NSDictionary?

O has an NSDictionary. There is an array inside the dictionary. I want to sort the dictionary and show its value in ascending order, so please help me, how can I get the sorted data?

+5
source share
2 answers

There are three NSDictionary functions ...

keysSortedByValueUsingSelector:keysSortedByValueUsingComparator:keysSortedByValueWithOptions:usingComparator:
+4
source

Use an NSSortDescriptor like this.

NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name"  ascending:YES];
[stories sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
recent = [stories copy];

Stories is the array you want to sort .recent is another mutable array that has sorted dictionary values. Change the "name" to the key value that you want to sort.

All the best

0
source

All Articles