Created
November 12, 2014 11:18
-
-
Save priore/14ced317638f694afacd to your computer and use it in GitHub Desktop.
NSObject set property values with NSDictionary
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
| // NSObject set property values with NSDictionary | |
| - (void)setValuesWithDictionary:(NSDictionary *)dict | |
| { | |
| if (dict != nil) { | |
| [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
| NSString *setPropName = [NSString stringWithFormat:@"set%@%@:", [[key substringWithRange:(NSRange){0, 1}] uppercaseString], [key substringFromIndex:1]]; | |
| if ([self respondsToSelector:NSSelectorFromString(setPropName)]) | |
| [self setValue:obj forKey:key]; | |
| }]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment