开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜