NSE*_*rer 14 iphone objective-c foundation ios
属于NSSet类的这两个方法之间的区别是什么:
-(BOOL)containsObject:(id)anObject
-(id)member:(id)object
Run Code Online (Sandbox Code Playgroud)
sos*_*orn 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.
Run Code Online (Sandbox Code Playgroud)
如果aSet中不存在anObject:
[aSet containsObject:anObject]; //return NO
[aSet member:anObject]; //return nil
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5288 次 |
| 最近记录: |