Does NSSet's containsObject: test for pointer equality or value equality?

核能气质少年 提交于 2019-12-03 14:35:40

问题


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?


回答1:


-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.



来源:https://stackoverflow.com/questions/8410606/does-nssets-containsobject-test-for-pointer-equality-or-value-equality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!