I have an NSMutableArray full of NSDictionary objects. Thus
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 sorted, so I am stuck with the order of objects inside it. I would like to sort the array of names in alphabetical order of objects for the key: @ "name" in the dictionary. Can this be done easily or will several levels of enumeration be required?
EDIT: I found the answer to SO in this question: NSMutableArray Sort
Class NSSortDescriptor.
NSSortDescriptor *sortName = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; [names sortUsingDescriptors:[NSArray arrayWithObject:sortName]]; [sortName release];
Anyone want free answers?
source share