Forum Navigation
You need to log in to create posts and topics.

Sorting an NSMutableArray of NSStrings

Posted by: fblistserve <fblistserve@...>

On Aug 7, 2012, at 5:52 PM, Brian S wrote:



What I’ve looked at:
The NSSortDescriptor looks appealing but the examples I’ve seen all require a key ( initWithKey: ). That would be fine for an array
of NSDictionaries( and is particularly nice for multiple key sorts ) but I don’t see how to make it work for an array of strings.

NSSortDescriptor *desc = [[NSSortDescriptor alloc]
                              initWithKey:@"desc"
                              ascending:YES
                              selector:@selector(localizedCaseInsensitiveCompare:)];
followed by:     [myNSMutableArray sortUsingDescriptors:[NSArray arrayWithObject:desc]];

btw: I’ve looked at:
NSArray *sortedValues = [myNSMutableArray sortedArrayUsingSelector: @selector(localizedCaseInsensitiveCompare:)];

but that puts the sorted data in a different array which is not known to my Combobox delegate methods. I could copy the sorted array to the NSMutableArray the comboBox knows about but this feels clumsy.

Brian S.


To unsubscribe, e-mail: fbcocoa-unsubscribe@welovegod.org For additional commands, e-mail: fbcocoa-help@freegroups.net