method_missing-like functionality in objective-c (i.e. dynamic delegation at run time)

后端 未结 1 592
情话喂你
情话喂你 2020-12-21 21:33

I\'m trying to transform one method call into another dynamically (at runtime).

For instance, I\'d like the following:

[obj foo]

t

相关标签:
1条回答
  • 2020-12-21 22:02

    You can use the method -forwardInvocation: for that. It takes a full NSInvocation object which represents the method call, and you can handle it however you wish. If you do this, you should also override -methodSignatureForSelector: to return the correct NSMethodSignature (required for -forwardInvocation: to work on unknown selectors). It's also recommended that you override -respondsToSelector: to declare that you can handle the selector in question.

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