本文介绍了NSSet的containsObject:测试指针相等还是值相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个
此外,对于 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:测试指针相等还是值相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!