indexOfObject vs. indexOfObjectIdenticalTo

情到浓时终转凉″ 提交于 2019-12-29 04:27:05

问题


What is the difference between these two NSArray methods?


回答1:


indexOfObjectIdenticalTo checks for the exact same id (same address). indexOfObject checks that isEqual: returns YES.




回答2:


The first uses isEqual: to find a matching object, while the second looks for the same object (i.e., the object at the same memory location).




回答3:


indexOfObjectIdenticalTo is far more faster than indexOfObject but it uses pointer comparison == instead of calling isEqual:

If you are searching for a pointer match, always use indexOfObjectIdenticalTo to get peak performance



来源:https://stackoverflow.com/questions/3167849/indexofobject-vs-indexofobjectidenticalto

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