Intercept method call in Objective-C

后端 未结 10 1413
被撕碎了的回忆
被撕碎了的回忆 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:17

    Intercepting method calls in Objective-C (asuming it is an Objective-C, not a C call) is done with a technique called method swizzling.

    You can find an introduction on how to implement that here. For an example how method swizzling is implemented in a real project check out OCMock (an Isolation Framework for Objective-C).

提交回复
热议问题