• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: multiple definitions of compare: -- design flaw?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >multiple definitions of compare: -- design flaw? (From: Brent Gulanowski <email@hidden>)

  • Prev by Date: Re: multiple definitions of compare: -- design flaw?
  • Next by Date: Re: multiple definitions of compare: -- design flaw?
  • Previous by thread: Re: multiple definitions of compare: -- design flaw?
  • Next by thread: Re: multiple definitions of compare: -- design flaw?
  • Index(es):
    • Date
    • Thread