NSSet的containsObject:测试指针相等或值相等吗?

时间:2021-04-07 16:21:25

Say I have an NSSet with a string in it. If I send containsObject: with another string which is a different pointer but the exact same string value, will that return YES?

假设我有一个带有字符串的NSSet。如果我发送containsObject:与另一个字符串,它是一个不同的指针,但完全相同的字符串值,将返回YES?

Also, is it the same story when it comes to removeObject:? I.e., different objects with different pointers but the same string values will cause removal?

另外,当涉及到removeObject时,它是同一个故事吗?即,具有不同指针但具有相同字符串值的不同对象将导致删除?

1 个解决方案

#1


40  

-containsObject: uses -isEqual: (and -hash) for equality testing. This applies to -removeObject: as well, and any other operations in NSSet that depend on some notion of equality.

-containsObject:使用-isEqual :(和-hash)进行相等性测试。这适用于-removeObject:以及NSSet中依赖于某些相等概念的任何其他操作。

#1


40  

-containsObject: uses -isEqual: (and -hash) for equality testing. This applies to -removeObject: as well, and any other operations in NSSet that depend on some notion of equality.

-containsObject:使用-isEqual :(和-hash)进行相等性测试。这适用于-removeObject:以及NSSet中依赖于某些相等概念的任何其他操作。