Can I do NSVariableFromString like NSClassFromString and NSSelectorFromString?

前端 未结 3 717
死守一世寂寞
死守一世寂寞 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: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.

提交回复
热议问题