Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indexOfObject vs. indexOfObjectIdenticalTo

What is the difference between these two NSArray methods?

like image 535
William Jockusch Avatar asked Jul 02 '10 17:07

William Jockusch


3 Answers

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

like image 82
Matthew Flaschen Avatar answered Oct 16 '22 09:10

Matthew Flaschen


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

like image 35
Marcelo Cantos Avatar answered Oct 16 '22 11:10

Marcelo Cantos


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

like image 2
Peter Lapisu Avatar answered Oct 16 '22 11:10

Peter Lapisu