On Feb 19, 2011, at 5:17 PM, Michael Crawford wrote:
> When I look inside the set, you will see that the value -1748299021286640132 
> is in the set.  However, when -containsObject is called, it returns NO.

Are you sure the objects you are dealing with are always NSNumbers? If one of 
them is an NSString, containsObject: will fail.

On Feb 19, 2011, at 5:28 PM, Scott Ribe wrote:
> 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.

That would strike me as very odd, since it would imply that the two instances 
aren't isEqual: to each other. (The containsObject: doc isn't explicit about 
whether it uses isEqual: to test for membership, but I assume so since member: 
does.)

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]);

--Andy

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to