priore

NSObject set property values with NSDictionary

Jul 7th, 2014
753
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // NSObject set property values with NSDictionary
  2. - (void)setValuesWithDictionary:(NSDictionary *)dict
  3. {
  4.     if (dict != nil) {
  5.         [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
  6.             NSString *setPropName = [NSString stringWithFormat:@"set%@%@:", [[key substringWithRange:(NSRange){0, 1}] uppercaseString], [key substringFromIndex:1]];
  7.             if ([self respondsToSelector:NSSelectorFromString(setPropName)])
  8.                 [self setValue:obj forKey:key];
  9.         }];
  10.     }
  11. }
RAW Paste Data