Created
May 28, 2013 07:43
-
-
Save khacanh/5661118 to your computer and use it in GitHub Desktop.
Extensions for NSDictionary
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+Ext.h" | |
@implementation NSDictionary(Ext) | |
-(float)floatForKey:(NSString*)key | |
{ | |
return [[self objectForKey:key] floatValue]; | |
} | |
-(int)intForKey:(NSString*)key | |
{ | |
return [[self objectForKey:key] intValue]; | |
} | |
-(BOOL)boolForKey:(NSString*)key | |
{ | |
return [[self objectForKey:key] boolValue]; | |
} | |
+ (NSDictionary *) dictionaryByMerging: (NSDictionary *) dict1 with: (NSDictionary *) dict2 { | |
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:dict1]; | |
[dict2 enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) { | |
[result setValue:obj forKey:key]; | |
}]; | |
return [result mutableCopy]; | |
} | |
- (NSDictionary *) dictionaryByMergingWith: (NSDictionary *) dict { | |
return [[self class] dictionaryByMerging: self with: dict]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment