How can I sort an NSArray containing NSDictionaries?

Here is an example. Imagines you have an array of dictionnaries. Ecah dictionnary have 2 keys “name” & “dateOfBirth”. You can sort your array by “name” like this :

// Sort array by name
NSSortDescriptor *Sorter = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:Sorter]];
[Sorter release];

Note that myArray is a NSMutableArray.

Leave a Comment