• 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: Best way to sort a dictionary by value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best way to sort a dictionary by value?


  • Subject: Re: Best way to sort a dictionary by value?
  • From: Keith Pritchard <email@hidden>
  • Date: Wed, 2 Oct 2002 01:41:40 +0100

On Tuesday, September 24, 2002, at 03:04 PM, Matt Neuburg wrote:
On Sun, 22 Sep 2002 20:46:45 +0100, Keith Pritchard <email@hidden> said:

I have a dictionary of dictionaries
I'd like to sort the dictionary1 keys by the values in dictionary 2....
eg. I'd like to get an array of dictionary1 keys that when iterated
through would result in a table of dictionary2 values sorted by, say,
date
Before I do something silly like trying to loop through dict2 using a
standard sort algorithm, does cocoa give me anything to make it easier?
I keep looking at keysSortedByValueUsingSelector but not exactly sure
how it would work

It would work great; keep looking at it. Since the selector is sent *to*
the items of dictionary1 they will need to be of a class that can respond
(or you can put a category on NSDictionary or NSMutableDictionary or
whatever the items are). Basically Cocoa simply lets you sort any way you
like. Consider alternatively sortedArrayUsingSelector: and
sortedArrayUsingFunction:. m.


Scott,

sorry to ask, could you give me a quick example or bit more info on what you meant by putting a category on NSDictionary?

My item of dictionary1 would indeed by a dictionary...

Thanks for your help,
Keith
_______________________________________________
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.

  • Prev by Date: Re: [NOT NEWBIE]launching tasks as root
  • Next by Date: Re: [NOT NEWBIE]launching tasks as root
  • Previous by thread: Leaking: NSFileHandle readInBackgroundAndNotify
  • Next by thread: AppleEvent question
  • Index(es):
    • Date
    • Thread