目标C对象按字符串名称命名吗? [英] Objective C object by string name?
本文介绍了目标C对象按字符串名称命名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以找到用特定字符串命名的对象.
Is it possible to find the object named with specific string.
例如,我可以在php中使用它
For example i can use that in php
$objectname="foo";
$foo="bar";
echo $$objectname="bar";
这可能吗?为此,objectbyname将是一个适当的功能.
is this possible? objectbyname would a proper function for this.
推荐答案
如果将命名对象存储为属性或某种字典,则有可能.然后您可以执行以下操作:
It could be possible if you stored named objects as properties or in some sort of dictionary. Then you could do something like this:
// Put object into dictionary
[dictionaryWithObjects setValue:someNamedObject forKey:@"someNamedObject"];
// and then retrieve it
id object = [dictionaryWithObjects valueForKey:@"someNamedObject"];
我不确定ObjectiveC是否支持该级别的元编程.
And I'm not sure ObjectiveC supports that level of metaprogramming.
这篇关于目标C对象按字符串名称命名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文