Apple document says that if I override isEqual:, then I need to override hashto make sure the hash value should be the same for two objects that are considered equalisEqual:
Then I read the hash docs, and below is part of it:
Therefore, either the hash method should not rely on any information about the internal state of objects, or you should make sure that information on the internal state of objects does not change while the object is in the collection.
My MyClass has several members, which are int and bool and NSArray, which contains the number of MyClass, and I want two instances of MyClass to be equal if all members are equal.
I have no problem with redefinition isEqual:, but for hash. As I understand it, I have hashto calculate the hash value by combining the hash value of the members using a bit operation, such as XOR or rotational shift.
The problem is how to implement hashin such a way as to meet the requirements of Apple, which are mentioned above. The docs say that the hash value should not rely on the internal state (which is the members), but I found that I should use them to calculate the value.
? , NSDictionary, , , hash. , hash, ?