Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: fbcocoaSorting an NSMutableArray of NSSt …
You need to log in to create posts and topics.
Sorting an NSMutableArray of NSStrings
1,678 Posts
#1 · August 7, 2012, 9:24 pm
Quote from Forum Archives on August 7, 2012, 9:24 pmPosted 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 arrayof 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:YESselector:@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
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 arrayof 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:YESselector:@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
Click for thumbs down.0Click for thumbs up.0