Rule Definition
If -isEqual: determines that two objects are equal, they must have the same hash value. This is why, if you override the isEqual method, you also need to override the hash method.
Remediation
Do not forget to override hash and isEqual at the same time
Violation Code Sample
@implementation MySubClass : MyClass
{
- (BOOL) isEqual:(id)anObject
{
return ([anObject hash]==[self hash])
}
}
Fixed Code Sample
@implementation MySubClass : MyClass
{
- (BOOL) isEqual:(id)anObject
{
return ([anObject hash]==[self hash])
}
- (int) hash
{
int newHash = ...
return newHash;
}
}
Reference
https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ObjectComparison.html
Related Technologies
Technical Criterion
CWE-1097 - Persistent Storable Data Element without Associated Comparison Control Element
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.