NSSet的containsObject:测试指针相等还是值相等? [英] Does NSSet's containsObject: test for pointer equality or value equality?
问题描述
说我有一个 NSSet
,里面有一个字符串。如果我发送 containsObject:
与另一个字符串,它是一个不同的指针,但完全相同的字符串值,将返回 YES
?
此外,对于 removeObject:
来说,
-containsObject:不同的对象有不同的指针但是相同的字符串值会导致删除?
使用 -isEqual:
(和 -hash
)进行相等测试。这也适用于 -removeObject:
以及 NSSet
中的任何其他操作,这取决于一些相等的概念。 / p>
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
?
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?
-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.
这篇关于NSSet的containsObject:测试指针相等还是值相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!