Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between containsObject: and member: methods of NSSet?

What is the diference between these two methods belonging to the NSSet class:

-(BOOL)containsObject:(id)anObject
-(id)member:(id)object 
like image 638
NSExplorer Avatar asked Jul 04 '11 02:07

NSExplorer


1 Answers

The answer lies in the return values. containsObject returns a YES or a NO depending on if the object you send belongs to that particular set.

member returns id, which means that it returns the actual object if that object is part of the set.

As an example, you have an NSSet, aSet, with anObject. anObject belongs to the set.

[aSet containsObject:anObject]; //returns YES
[aSet member:anObject]; //If the set contains an object equal to object (as determined by isEqual:) then that object (typically this will be object), otherwise nil.

If anObject does not exist in aSet:

[aSet containsObject:anObject]; //return NO
[aSet member:anObject]; //return nil
like image 155
sosborn Avatar answered Oct 31 '22 19:10

sosborn