I suggest you three unpleasant ways to do it in +(void)load. In each case, name your method MyCategory_method or so.
- class_getMethodImplementation () and class_replaceMethod (). Store the old IMP and call it directly. You need to get the encoding of the method type. Note that you can just use the regular C function ...
- class_getInstanceMethod (), method_getImplementation (), method_setImplementation (). As above, but you do not need to get a method type encoding.
- class_getInstanceMethod () for both methods, and then method_exchangeImplementations (). Call MyCategory_method to get the original implementation. This is the easiest way to do this.
Sometimes, this is the only reasonably simple way to get him to do what you want ...
EDIT: And just do it if you know what you are doing!
source
share