Re: Comparing NSDictionary woes
Re: Comparing NSDictionary woes
- Subject: Re: Comparing NSDictionary woes
- From: Ken Tozier <email@hidden>
- Date: Sun, 22 Jul 2007 19:37:56 -0400
On Jul 22, 2007, at 6:25 PM, Chris Hanson wrote:
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.)
Thanks Chris. Good good to know but the current compare problems are
between two plain vanilla dictionaries with nothing but standard
plist types in them.
Ken
_______________________________________________
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