属于NSSet类的这两个方法有什么区别:
-(BOOL)containsObject:(id)anObject
-(id)member:(id)object
答案 0 :(得分:20)
答案在于返回值。 containsObject返回YES或NO,具体取决于您发送的对象是否属于该特定集。
成员返回id,这意味着如果该对象是该集合的一部分,它将返回实际对象。
作为一个例子,你有一个带有anObject的NSSet,aSet。 anObject属于集合。
[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.
如果aSet中不存在anObject:
[aSet containsObject:anObject]; //return NO
[aSet member:anObject]; //return nil