Let's say I have this method -isEqual: ::
- (BOOL)isEqual:(MyObject*)aObject { if (![aObject isKindOfClass:[MyObject class]]) { return NO; } return ([self.dateString isEqualToString:aObject.dateString] || [self.date isEqual:aObject.date]) && ((!self.title && !aObject.title) || [self.title isEqualToString:aObject.title]); }
So, two objects are considered equal if either date OR dateString are equal and title are equal. Assume here that date and dateString should not be zero, otherwise we would have to check this. We also assume that there is no known relationship between date and dateString .
How can I implement the corresponding -hash method so that it -hash requirement that two equal objects have the same hash?
I tried to implement it by following this excellent algorithm , but it is difficult for me to translate the OR condition of two dates into the corresponding hash method.
(Admittedly, this question is somewhat academic, because one can doubt whether this approach makes sense. Since I'm interested in finding a common solution, do not send an answer, I have to change my isEqual: Except that formally may be proved that a suitable -hash method cannot exist.)
source share