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: Andy Lee <email@hidden>
- Date: Sat, 19 Feb 2011 22:08:44 -0500
On Feb 19, 2011, at 6:08 PM, Andy Lee wrote:
> I just did a quick test and confirmed that you do get two different instances with the same hash, but they are in face isEqual: to each other and hence their presence in a set is detected, as I would expect.
>
> NSNumber *one = [NSNumber numberWithLongLong:1];
> NSNumber *another = [NSNumber numberWithLongLong:1];
> NSSet *set = [NSSet setWithObject:another];
>
> NSLog(@"+++ one %p, hash = %ld -- another %p, hash = %ld -- is eq = %d, contains one = %d, contains another = %d",
> one, [one hash], another, [another hash], [one isEqual:another], [set containsObject:one], [set containsObject:another]);
Whoops, actually I got the same instance using 1, presumably because NSNumber keeps a few low number instances cached. What I said above is true if I retry with 123456789.
--Andy
_______________________________________________
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