Intercept method call in Objective-C

后端 未结 10 1403
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 13:34

Can I intercept a method call in Objective-C? How?

Edit: Mark Powell\'s answer gave me a partial solution, the -forwardInvocation

10条回答
  •  醉梦人生
    2020-12-02 14:28

    To do something when a method is called, you could try an events based approach. So when the method is called, it broadcasts an event, which is picked up by any listeners. I'm not great with objective C, but I just figured out something similar using NSNotificationCenter in Cocoa.

    But if by "intercept" you mean "stop", then maybe you need more logic to decide wether the method should be called at all.

提交回复
热议问题