Re: -[NSSet containsObject:] returns NO when it should return YES
Re: -[NSSet containsObject:] returns NO when it should return YES
- Subject: Re: -[NSSet containsObject:] returns NO when it should return YES
- From: Scott Ribe <email@hidden>
- Date: Sat, 19 Feb 2011 15:28:31 -0700
On Feb 19, 2011, at 3:17 PM, Michael Crawford wrote:
> I assumed that the -[NSObject hash] method is used to determining equality and that to different NSNumber instances will hash out to the same value if they have the same 64-bit value stored inside.
I'm pretty sure that, for instance, two calls to [NSNumber numberWithLongLong: 1] will produce two different objects, and though they may fall into the same hash bucket if the hash method uses the numeric value, they will still not be treated as the same object by -containsObject.
If you look at the -member method instead, you'll see that it uses isEqual, so maybe that would do what you want, or maybe not, depending on how isEqual is implemented by NSNumber. -filteredSetUsingPredicate would seem to do it, but would be slower since it will iterate the whole set.
Personally, though my approach may not be terribly popular with the Cocoa crowd, I'd use std::set ;-)
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
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