Re: Sorting an NSDictionary?
Re: Sorting an NSDictionary?
- Subject: Re: Sorting an NSDictionary?
- From: "Michael B. Johnson" <email@hidden>
- Date: Mon, 14 Jan 2002 22:55:47 -0800
On Monday, January 14, 2002, at 10:14 PM, cocoa-dev-
email@hidden wrote:
Send cocoa-dev mailing list submissions to
email@hidden
To subscribe or unsubscribe via the World Wide Web, visit
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
or, via email, send a message with subject or body 'help' to
email@hidden
You can reach the person managing the list at
email@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of cocoa-dev digest..."
Today's Topics:
1. Re: Sorting an NSDictionary? (Erik M. Buck)
2. Sub-pixel text placement (Dustin Mierau)
3. Re: NSWorkspaceDidTerminateApplicationNotification bug? (Mike
Davis)
4. Re: Drawing an image in a CustomView (Erik M. Buck)
5. Re: NSWorkspaceDidTerminateApplicationNotification bug? (Bill
Bumgarner)
--__--__--
Message: 1
From: "Erik M. Buck" <email@hidden>
To: "Jeff Galyan" <email@hidden>, "Cocoa-Dev List"
<email@hidden>
Subject: Re: Sorting an NSDictionary?
Date: Mon, 14 Jan 2002 22:12:48 -0600
Organization: EMB & Assocites Inc.
As the NSDictionary and NSMapTable and other documentation will tell
you,
all objects stored must implement the informal protocol that includes
the
methods -compare: and -hash. Since NSObject already implements these
methods, you are in good shape unless you want to customize the
behavior.
If you do implement -compare: or -hash, remember that any two objects
that
have the same hash must also compare as equal or bad things will happen.
Another UNDOCUMENTED as far as I know issue is that dictionary keys are
COPIED and therefore objects used as keys must conform to the NSCopying
(sp?) protocol.
This bit me as well when I first start using dictionaries, but it's
quite well documented, once you look - in NSDictionary, I see:
Each value object receives a retain message before being added to the
dictionary. In contrast, each key is copied (using copyWithZone:; keys
must conform to the NSCopying protocol), and the copy is added to the
dictionary.
--> Michael B. Johnson, Ph.D. -- email@hidden
--> Studio Tools, Pixar Animation Studios
-->
http://xenia.media.mit.edu/~wave