I would like to assign each item from a dictionary into my object using a "for...in" loop
I have a NSDictionary like that :
{"user_id" : "1", "user_name" : "John"}
And I have an NSObject with variable :
NSString *user_id;
NSString *user_name
With a for in loop, I want to assign each item from my NSDictionary in my NSObject
for (NSString *param in userDictionary) {
}
How I can do that ?
Thanks,
Have a look at the NSObject class method:
- (void)setValue:(id)value forKey:(NSString *)key;
For example:
[userDictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){
[myObject setValue:obj forKey:(NSString *)key];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With