I have an NSMutableArray full of NSDictionary objects. Like so
NSMutableArray *names = [[NSMutableArray alloc] init];
for (NSString *string in pathsArray) {
NSString *path = [NSString stringWithFormat:@"/usr/etc/%@",string];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:string,@"name",path,@"path",nil];
}
pathsArray is not sortable, so I’m stuck with the order of objects inside of it. I would like to sort the names array in alphabetical order of the objects for the key: @”name” in the dictionary. Can this be done easily or will it take several levels of enumeration?
EDIT: I Found the answer on SO in this question: Sort NSMutableArray
NSSortDescriptor class.
NSSortDescriptor *sortName = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[names sortUsingDescriptors:[NSArray arrayWithObject:sortName]];
[sortName release];
Anyone care to get some free answer points?
Try something like this: