开发者

How To Set Class Variables By Key

开发者 https://www.devze.com 2023-03-28 18:31 出处:网络
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?

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

精彩评论

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