Last active
August 29, 2015 14:02
-
-
Save hlung/c178139958cb61c009b2 to your computer and use it in GitHub Desktop.
An example for class equality method implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface FGEntityLine : NSObject | |
@property (readonly, nonatomic) NSUInteger companyId; | |
@property (readonly, nonatomic) NSUInteger brandId; | |
@property (readonly, nonatomic) NSUInteger propertyId; | |
/** Returns YES if all identifiers are equal. */ | |
- (BOOL)isEqualToEntityLine:(FGEntityLine *)line; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation FGEntityLine | |
#pragma mark - equality | |
- (BOOL)isEqualToEntityLine:(FGEntityLine *)line { | |
if (!line) { | |
return NO; | |
} | |
BOOL haveSameKindOfClass = [self isKindOfClass:line.class]; | |
BOOL haveEqualIdentifiers = (self.companyId == line.companyId) && (self.brandId == line.brandId) && (self.propertyId == line.propertyId); | |
return haveSameKindOfClass && haveEqualIdentifiers; | |
} | |
- (BOOL)isEqual:(id)object { | |
if (self == object) { | |
return YES; | |
} | |
return [self isEqualToEntityLine:(FGEntityLine *)object]; | |
} | |
- (NSUInteger)hash { | |
return self.companyId ^ self.brandId ^ self.propertyId; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment