Re: Implementing isEqual: and hash
Re: Implementing isEqual: and hash
- Subject: Re: Implementing isEqual: and hash
- From: Phil <email@hidden>
- Date: Sun, 24 Aug 2008 00:00:23 +1200
On Sat, Aug 23, 2008 at 11:41 PM, Graham Cox <email@hidden> wrote:
> I have a class for which equality can be defined as having the same internal
> string value (which happens to be a UUID-turned-string). I can easily
> implement isEqual: based on that but the docs say I also need to implement
> -hash. Any pointers on what is a good way to do that? Could I just safely
> defer to the -hash returned by the string in question?
>
If you're deferring both -isEqual: and -hash to an NSString, you'll be
fine. Hash doesn't need to be anything complicated (although a good
distribution is nice), just as long as two objects that return YES for
-isEqual: return the same value for -hash (the inverse doesn't have to
be true).
Phil
_______________________________________________
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