I have a class that ideally will read the methods of any class passed in and then display all of them on the same selector at runtime before sending them to the original selector.
It works right now, but I can only do this one method at a time. The problem seems to be that as soon as I start the first method, my IMP, to catch and forward the method, has now been replaced by other IMP methods. Any further attempts to ruin this because they use the recently replaced IMP to replace others.
1) So, I have MethodA, MethodB and CustomCatchAllMethod.
2) I change the MethodA method to CustomCatchAllMEthod. MethodA-> CustomCatchAllMethod, CustomCatchAllMethod-> MethodA
3) Now I'm trying to change to MethodB using CustomCatchAllMethod, but since CustomCatchAllMethod is now = MethodA, MethodB becomes MethodA and MethodA-> MethodB.
So, how do I get / copy a new instance of my IMP for each new selector I want to intercept?
Here's a rough layout of the above thread:
void swizzle(Class classImCopying, SEL orig){ SEL new = @selector(catchAll:); Method origMethod = class_getInstanceMethod(classImCopying, orig); Method newMethod = class_getInstanceMethod(catchAllClass,new); method_exchangeImplementations(origMethod, newMethod); } //In some method elsewhere //I want this to make both methodA and methodB point to catchAll: swizzle(someClass, @selector(methodA:)); swizzle(someClass, @selector(methodB:));
ios objective-c objective-c-runtime swizzling
Jack freeman
source share