Objective-C dynamic properties at runtime?

后端 未结 3 2007
一整个雨季
一整个雨季 2020-12-02 17:56

Is it possible to create an Objective-C class that can have an arbitrary number of dynamic properties at runtime?

I want to be able to call mySpecialClass.anyP

3条回答
  •  [愿得一人]
    2020-12-02 18:19

    Guillaume is right. forwardInvocation: is the way to go. This answer gives some more details: method_missing-like functionality in objective-c (i.e. dynamic delegation at run time)

    This has even more details: Equivalent of Ruby method_missing in Objective C / iOS

    And these are some other lesser known Obj-C features that might help you: Hidden features of Objective-C

    Enjoy!

提交回复
热议问题