SHARE
TWEET

NSObject set property values with NSDictionary

priore Jul 7th, 2014 675 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top