本文介绍了我可以做NSVariableFromString像NSClassFromString和NSSelectorFromString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,所以我注意到你可以做NSClassFromString和NSSelectorFromString。

Right so I have noticed that you can do NSClassFromString and NSSelectorFromString.

是否可以做像NSVariableFromString?

Is it possible to do something like NSVariableFromString?

推荐答案

目标C运行库有很多的好处,你的消费。

The objective C runtime has lots of goodies for your consumption.

如果你想要一个iVar,你可以调用object_getInstanceVariable一个字符串名称。

If you want an iVar, you can call object_getInstanceVariable with a string name.

如果你想要变量,这需要更多的工作,它们必须是全局可见的链接器。您可以为此目的使用CFBundleGetDataPointerForName。

If you want variables, it's a bit more work, and they have to be globally visible to the linker. You can use CFBundleGetDataPointerForName for that purpose.

请务必阅读文档,了解有关运行时信息的限制和特定信息,以及在不同平台上可用的内容。

Be sure to read the documentation for restrictions and specific information about runtime information, and the availability of stuff on different platforms.

这篇关于我可以做NSVariableFromString像NSClassFromString和NSSelectorFromString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:04