Can I do NSVariableFromString like NSClassFromString and NSSelectorFromString?

前端 未结 3 693
死守一世寂寞
死守一世寂寞 2021-01-16 12:25

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

Is it possible to do something like NSVariableFromString?

相关标签:
3条回答
  • 2021-01-16 13:21

    No. Compiled applications don't contain variable names except when debug info is included and it usually isn't for release applications.

    0 讨论(0)
  • 2021-01-16 13:26

    You can get values from strings using NSScanner but, as JemeryP notes, at runtime variable names have generally been converted to pointers and memory addresses.

    0 讨论(0)
  • 2021-01-16 13:29

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

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

    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.

    0 讨论(0)
提交回复
热议问题