Re: Problem with NSSet's containsObject: and member: methods
Re: Problem with NSSet's containsObject: and member: methods
- Subject: Re: Problem with NSSet's containsObject: and member: methods
- From: Chris Kane <email@hidden>
- Date: Sat, 12 Apr 2003 19:08:13 -0700
On Friday, April 11, 2003, at 05:03 AM, Thomas Deniau wrote:
I've a NSMutableSet of custom objects of class A.
I've overridden isEqual: in A and I NSLog() whenever the method is
called.
Suppose the set has three elements b, c, d of class A, and we have a
given
object e of class A. [d isEqual:e] returns TRUE, and [b isEqual:e],[c
isEqual:e] return FALSE.
When I call [set containsObject:e] or [set member:e] I get FALSE and
nil (I
would have expected TRUE !).
Did you also override the -hash method? If not, that is your problem.
NSObject's documentation will talk about -hash; there might be other
discussion in some of the Cocoa intro docs. Make sure you read about
the hash/isEqual invariant and make sure you ensure that with your
implementation.
As to your other question, NSSet uses hashing rather than simply being
an array of objects, and this allows it to discount most of the objects
from being candidates in the search. [Which only works if the invariant
is properly maintained, of course.]
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.