Re: multiple definitions of compare: -- design flaw?
Re: multiple definitions of compare: -- design flaw?
- Subject: Re: multiple definitions of compare: -- design flaw?
- From: Don Arbow <email@hidden>
- Date: Thu, 10 Jul 2003 12:13:23 -0700
On Thursday, July 10, 2003, at 08:34 AM, Brent Gulanowski wrote:
Is there a better solution to avoid the compiler warning? I am sorting
dictionaries based on NSNumber and/or NSString objects contained
therein.
Do you mean that you are sorting arrays of dictionaries? Assuming you
are using an NSMutableArray, all you need to do is use
sortUsingFunction:, coding your comparison function like this:
int compareByString(id dict1, id dict2, void *key) {
NSString* stringA = (NSString *)[(NSDictionary *)dict1
objectForKey:(NSString *)key];
NSString* stringB = (NSString *)[(NSDictionary *)dict2
objectForKey:(NSString *)key];
return [stringA compare:stringB];
}
call it like this (you pass the dictionary key in the context argument):
[myArray sortUsingFunction:compareByString context:@"myDictionaryKey"];
Don
_______________________________________________
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.