How To Set Class Variables By Key
I'm updating one of my models and I'm sending in a dictionary of attributes with their updated values. Is there an easy way to access my instance variables by their name?
e.g.
[myObject setValueByVariableName:@"varName" value:@"new_value"];
Update
I think I might have answered my own question ... testing it with
[myObject setValue:(id)va开发者_如何学Pythonl forKey:(NSString*)key];
[myObject setValue:@"some_value" forKey:@"some_instance_variable"];
See the Key-Value Coding (KVC) documentation here: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html
精彩评论