Objective-C Tips & Trick - Prioregroup.com
[Objective-C] NSObject set property values with NSDictionary
       
back

// 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];
        }];
    }
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com