Say I have an object someObjectand NSMutableArray *someArray. I am not sure what someObjectis in the array, but if so, I want to delete it. There are two options:
Case 1:
if([someArray indexOfObject:someObject] != NSNotFound)
[someArray removeObject:someObject];
Case 2:
[someArray removeObject:someObject]
In case 2, if the object does not exist in the array, nothing happens. My question is that case 2 is more efficient, since in case 1 I will need to search for the array and see if it exists, and if so, I delete it, but I assume that removeObject:it is looking for the array again?
source
share