Swizzling and super

后端 未结 1 1309
暗喜
暗喜 2021-01-27 01:12

I am trying to swizzle the canPerformAction:withSender: method for UIResponder and all its subclasses which have overridden this method.

I am doing this by storing the o

相关标签:
1条回答
  • 2021-01-27 01:52

    After the swizzle the -original with -custom:

    -(void)custom {
        [self custom]; // calls -original
    }
    
    -(void)original {
        [self original]; // calls -custom
    }
    

    Said that, if you have the methods swizzled in the superclass, objc_msgSendSuper will do the same: call original for custom and versa giving you the recursion.


    -(void)custom {
        [self original]; // calls -custom, makes recursion
    }
    
     -(void)original {
        [self custom]; // calls -original, makes recursion
    }
    
    0 讨论(0)
提交回复
热议问题