Re: Comparing NSDictionary woes
Re: Comparing NSDictionary woes
- Subject: Re: Comparing NSDictionary woes
- From: Chris Hanson <email@hidden>
- Date: Sun, 22 Jul 2007 15:25:35 -0700
On Jul 22, 2007, at 2:20 PM, Ken Tozier wrote:
Do your objects satisfy that test?
They should.
If they are custom subclasses of NSObject or some other class, and you
haven't implemented -isEqual: yourself, chances are they *don't*.
When implementing "value" classes, you *must* explicitly implement -
isEqual: and -hash on your objects in order for them to compare
identical based on their contents. Otherwise, your class will fall
back to -[NSObject isEqual:] which is a pointer-equality test and -
[NSObject hash] which isn't based on the contents of the object.
Also, you should have unit tests for your classes so you can say for
certain whether -isEqual: and -hash are behaving correctly. (The rule
is that -hash must return the same value for objects that respond YES
to -isEqual:, but objects that respond NO to -isEqual: don't
necessarily need different hashes.)
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden