Is there a way to determine if a class is suitable as a key and will work as you expect, for example I want to use NSIndexPath as a key in NSDictionary but I don’t know for certain if two different NSIndexPath instances with the same integer values will always return the same hash value.
Share
Apple’s NSObject’s isEqual document says:
Look the following code:
Output Result:
The implementation of NSObject isEqual is that comare the address of two objects,
and hash implementation is that return object’s address.
NSIndexPath is inherited from NSObject, according to NSIndexPath isEqual output result,
NSIndexPath’s isEqual implementation should override superclass’s isEqual method, and NSIndexPath also override superclass’s hash method.
In attition, NSIndexPath also conform to the NSCopying protocol.
So NSIndexPath can be used as the Key class of NSDictionary.