<分区>
<分区>
我有一个 NSString *str = @"abc"
和一个具有名为“abc”的属性的对象。如何使用“str”访问该属性。我知道我必须使用 objective-c 运行时,但不知道它是否可能。我不想设置该属性,而是想使用该属性,就像如果属性“abc”是一个数组,而不是我想向该数组添加一个对象。我经历过
this链接并发现重新开始没什么帮助。
最佳答案
为此,您需要使用 Key-Value Coding :
This document describes the
NSKeyValueCoding
informal protocol, which defines a mechanism allowing applications to access the properties of an object indirectly by name (or key), rather than directly through invocation of an accessor method or as instance variables.
关于ios - 从包含对象名称的字符串访问对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17101269/