Created
June 23, 2016 16:40
-
-
Save lengocgiang/53e7c0a4d144b35f6db3c9ac5c4e6f35 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
// find depth key in NSDictionary | |
- (id)findKey:(NSString *)keyname inObject:(id)object { | |
for (id subKey in object) { | |
id subObject = [object objectForKey:subKey]; | |
if ([subKey isEqualToString:keyname]) { | |
return subObject; | |
} else if ([subObject isKindOfClass:[NSDictionary class]]) { | |
return [self findKey:keyname inObject:subObject]; | |
} else if ([subObject isKindOfClass:[NSArray class]]) { | |
return [self findKey:keyname inArray:subObject]; | |
} | |
} | |
return nil; | |
} | |
- (id)findKey:(NSString *)keyname inArray:(NSArray *)array { | |
for (id sub in array) { | |
if ([sub isKindOfClass:[NSDictionary class]]) { | |
return [self findKey:keyname inObject:sub]; | |
} else if ([sub isKindOfClass:[NSArray class]]) { | |
return [self findKey:keyname inObject:sub]; | |
} | |
} | |
return nil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment