Re: Sorting NSMutableArray by specified key?
Re: Sorting NSMutableArray by specified key?
- Subject: Re: Sorting NSMutableArray by specified key?
- From: Ondra Cada <email@hidden>
- Date: Sun, 30 Jun 2002 20:43:40 +0200
On Sunday, June 30, 2002, at 07:53 , Aidas wrote:
I would like to sort NSMUtableArray by specified key alphabeticaly.
What does it mean? There are no keys in arrays at all.
IS it possible somehow?
Sure -- see sortUsingSelector: and sortUsingFunction... methods. If the
"key" meant the array contains dictionaries, then you can eg. do this:
int _compareKeys(id left, id right, void *ctxt) {
return [(NSString*)[left objectForKey:(id)ctxt] compare:[right
objectForKey:(id)ctxt]];
}
...
[array sortUsingFunction:_compareKeys context:@"the key"];
(caveat: not tested, might contain typos or simple overlooked-this bugs.
Principle's sound for sure, though -- used that myself many times)
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.