这是我的 isEqual 和哈希自定义运算符
- (BOOL)isEqual:(id)object;
{
BGSearchParameter * theOther = (BGSearchParameter *)object;
BOOL isTheOtherEqual;
isTheOtherEqual = isTheOtherEqual && [self.Location isEqual:theOther.Location];
isTheOtherEqual = isTheOtherEqual && [self.keyword isEqual:theOther.keyword];
isTheOtherEqual = isTheOtherEqual && (self.Distance == theOther.Distance);
isTheOtherEqual = isTheOtherEqual && (self.SortByWhat == theOther.SortByWhat);
isTheOtherEqual = isTheOtherEqual && (self.startFrom == theOther.startFrom);
isTheOtherEqual = isTheOtherEqual && (self.numberOfIDstoGrab == theOther.numberOfIDstoGrab);
return isTheOtherEqual;
}
- (NSUInteger)hash
{
NSUInteger returnValue=0;
returnValue ^= self.Location.hash;
returnValue ^= self.keyword.hash;
return returnValue;
}
那个做这项工作。但是,假设我想将距离和 startfrom 合并到哈希中。
我想我会简单地添加:
returnValue ^= self.Distance;
这是一个错误,因为它不兼容。
那么我应该怎么做呢?