In Cocoa, equality of an object is done using isEqual: and hash:
https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
From the notes for isEqual: ::
If two objects are equal, they must have the same hash value. This last point is especially important if you define isEqual: in a subclass and intend to put instances of this subclass in the collection. Make sure you also define a hash in your subclass.
Your subclasses will need to implement both of these functions so that they return the same thing. Once they do, they can be used correctly in Cocoa Collections.
The reason your NSSet equality won't work is because the sets use hashes (it is stored as a hash table), so if you only implemented isEqual: then there is a chance (good chance) that their hashes will differ .
source share