Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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