Re: When do I need to override hash?
Re: When do I need to override hash?
- Subject: Re: When do I need to override hash?
- From: Alastair Houghton <email@hidden>
- Date: Fri, 21 Aug 2009 09:19:17 +0100
On 21 Aug 2009, at 03:45, Jeff Laing wrote:
The -hash method is important for objects that are used as keys in
associative collections.
[snip]
So, in practice, it's perfectly safe in 99.9% of cases to base your
hash off your object's properties. In the specific case when you're
mutating objects that are keys in associative collections
(NSDictionary and NSSet being the primary examples, along with their
CoreFoundation counterparts) ...
Is there any way that you can tell that some higher-level technology
you are using (CoreData?) is putting your objects into an NSSet?
That's presumably a hidden implementation detail which you can't
assume one way or the other with any safety?
If it did that without documenting that mutating them would be A Bad
Thing, then that would be a bug in the higher-level technology in
question IMO.
In any case, if a higher layer was storing references to your objects,
it's more likely to want the thing it stores them in to work based on
the pointers (i.e. the object's identity), rather than the object's
value. So it's quite unlikely that this would be a problem in
practice either.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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