Skip to content

Instantly share code, notes, and snippets.

@dnnta
Created January 9, 2013 15:10
Show Gist options
  • Save dnnta/4493852 to your computer and use it in GitHub Desktop.
Save dnnta/4493852 to your computer and use it in GitHub Desktop.
Compare two NSDictionary
-(BOOL)isEtalonDictionary:(NSDictionary *)etalonDictionary sameAs:(NSDictionary *)dictionary{
BOOL res = NO;
for (id item in etalonDictionary){
NSObject *secondObject = [dictionary objectForKey:item];
if (secondObject == nil)
return NO;
else{
NSObject *value = [etalonDictionary objectForKey:item];
if ([value isKindOfClass:[NSString class]]){
NSString *string = (NSString *) value;
if ([string isEqualToString:(NSString *) secondObject]){
res = YES;
} else {
return NO;
}
}
if ([value isKindOfClass:[NSNumber class]]){
NSNumber *number = (NSNumber *) value;
if([number isEqualToNumber:(NSNumber *) secondObject])
res = YES;
else
return NO;
}
if ([value isKindOfClass:[NSDictionary class]]){
res = [self isEtalonDictionary:(NSDictionary *) value sameAs:(NSDictionary *) secondObject];
if (!res){
return NO;
}
}
}
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment