When do I need to override hash?
When do I need to override hash?
- Subject: When do I need to override hash?
- From: Gideon King <email@hidden>
- Date: Thu, 20 Aug 2009 09:28:35 +1000
I was just looking up the documentation to remind myself of the
difference between isEqual: and isEqualTo: and saw that for your own
custom objects to behave nicely in a collection, it apparently needs
to override both isEqual: and hash.
But when I look at the specific documentation for things like NSArray
and NSSet, it says that the actual comparison is done with a call to
isEqual: (although it does mention that you should override hash too).
But when I look at the likes of the Cocoa Fundamentals Guide at http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html
the example shows only overriding isEqual: (in the Object Comparison
section).
So do I need to override hash too? If so, are there any
recommendations as to how to determine the hash easily?
Thanks
Gideon
_______________________________________________
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