Created
October 24, 2015 17:17
-
-
Save obyknovenius/f06c1f127d1de6c1ef5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Person | |
@property NSString *name; | |
@property NSDate *birthday; | |
- (BOOL)isEqualToPerson:(Person *)person; | |
@end | |
@implementation Person | |
- (BOOL)isEqualToPerson:(Person *)person { | |
if (!person) { | |
return NO; | |
} | |
BOOL haveEqualNames = (!self.name && !person.name) || [self.name isEqualToString:person.name]; | |
BOOL haveEqualBirthdays = (!self.birthday && !person.birthday) || [self.birthday isEqualToDate:person.birthday]; | |
return haveEqualNames && haveEqualBirthdays; | |
} | |
#pragma mark - NSObject | |
- (BOOL)isEqual:(id)object { | |
if (self == object) { | |
return YES; | |
} | |
if (![object isKindOfClass:[Person class]]) { | |
return NO; | |
} | |
return [self isEqualToPerson:(Person *)object]; | |
} | |
- (NSUInteger)hash { | |
return [self.name hash] ^ [self.birthday hash]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment