问题
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