- (void)removeObjectsInArray:(NSArray *)otherArray
Removes from the receiving array the objects in another given array.
This method is similar to removeObject:, but allows you to efficiently
remove large sets of objects with a single operation. If the receiving
array does not contain objects in otherArray, the method has no effect
(although it does incur the overhead of searching the contents). This
method assumes that all elements in otherArray respond to hash and
isEqual:.
I understand that removeObjectsinArray require isEqual
Why does it need to implement objects either?
From the NSObject documentation:
If you override
-isEqual:, it’s recommended to also override-hash. So that’s the first reason – it would be inconsistent for them not to make the same recommendation in the-removeObjectsInArray:documentation.The second reason is more subtle. As an experienced developer, you could assume
-hashwould not be used for the implementation of-removeObjectsInArray:(or find it out by experimentation), and that you can get away with not implementing it on your objects. However, Apple are making clear that they reserve the right to use-hashin their implementation, if they feel it would be worthwhile optimisation, and that you should implement it just in case.(I have no clue whether or not they use it in their current implementation)