Re: Sorting an NSArray containing NSDictionaries
Re: Sorting an NSArray containing NSDictionaries
- Subject: Re: Sorting an NSArray containing NSDictionaries
- From: Ondra Cada <email@hidden>
- Date: Wed, 29 Aug 2001 11:40:02 +0200
samgoldman,
>
>>>>> email@hidden (s) wrote at Tue, 28 Aug 2001 19:29:18 -0700:
s> I get the data into an array with no problem, and can access all the
s> data within. But when I add a word, it isn't in alphabetical order, but
s> I want it to be in the table view. In short, what I need to do is sort
s> an array based on what is in dictionaries that are contained within. It
s> would be best if I could sort by the english word.
One possibility is
static int _compareByKey(id left,id right,void *ctxt) {
return [[left objectForKey:ctxt] compare:[right objectForKey:ctxt]];
}
...
NSMutableArray *a;
...
[a sortArrayUsingFunction:_compareByKey context:@"English"]
Check the NSArray documentation for more details.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc