Created
August 19, 2010 04:04
-
-
Save tylerhall/536994 to your computer and use it in GitHub Desktop.
NSDictionary category that lets you retrieve a value from a dictionary of dictionaries in a single statement. I'm gonna feel really dumb if there was already a way to do this.
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
#import <Foundation/Foundation.h> | |
@interface NSDictionary (EmbeddedValue) | |
- (id)embeddedValueWithKeys:(NSArray *)keys; | |
@end |
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
#import "NSDictionary+Embedded.h" | |
@implementation NSDictionary (EmbeddedValue) | |
- (id)embeddedValueWithKeys:(NSArray *)keys { | |
id obj = self; | |
for(id key in keys) { | |
obj = [obj objectForKey:key]; | |
if(obj == nil) | |
return nil; | |
} | |
return obj; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment