Created
August 21, 2013 15:52
-
-
Save BigAB/6296298 to your computer and use it in GitHub Desktop.
An Equality test thing that though I am deleting I think I should keep around incase something similar comes up in the future.
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 ABSearch | |
{} | |
- (BOOL)isEqualToSearch:(GBSearch *)search { | |
if (self == search) | |
return YES; | |
static NSString *objTypeIndicator = @"T@"; | |
static NSString *timePropertyName = @"time"; | |
static NSString *locationPropertyName = @"location"; | |
unsigned int outCount, i; | |
objc_property_t *properties = class_copyPropertyList([self class], &outCount); | |
for (i = 0; i < outCount; i++) { | |
NSString *attributes = [NSString stringWithUTF8String:property_getAttributes(properties[i])]; | |
NSString *type = [attributes substringToIndex:2]; | |
BOOL itsAnObject = [type isEqualToString:objTypeIndicator]; | |
NSString *key = [NSString stringWithUTF8String:property_getName(properties[i])]; | |
if ([key isEqualToString:timePropertyName]) continue; | |
id myVal = [self valueForKey:key]; | |
id sVal = [search valueForKey:key]; | |
if ([key isEqualToString:locationPropertyName]) { | |
CLLocation *loc1 = myVal; | |
CLLocation *loc2 = sVal; | |
if ([loc1 distanceFromLocation:loc2] == 0) { | |
continue; | |
} else { | |
return NO; | |
} | |
} | |
if (myVal == nil && sVal == nil) { | |
continue; | |
} | |
if (itsAnObject) { | |
if (![myVal isEqual:sVal]) { | |
return NO; | |
} | |
} else { | |
if (myVal != sVal) { | |
return NO; | |
} | |
} | |
} | |
free(properties); | |
return YES; | |
} | |
-(BOOL)isEqual:(id)other { | |
if([super isEqual:other]) | |
return YES; | |
if(!other || ![other isKindOfClass:[self class]]) | |
return NO; | |
return [self isEqualToSearch:other]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment