Lemme break this down into two, as I just can't get the connection between your two questions.
I am. Create a new method with the "old" implementation and change the name to a schema such as "___ name"
This is pretty easy, although I don’t understand how this could solve your problem. You still cannot pass arguments to the variational function for such a method (and you are right, this cannot be done in C).
IMP swapImpForSelector(Class cls, SEL sel, IMP newImp) { Method m = class_getInstanceMethod(cls, sel); IMP oldImp = method_setImplementation(m, newImp); NSString *newSel = [NSString stringWithFormat:@"__prefixed_%@", NSStringFromSelector(sel)]; const char *type = method_getTypeEncoding(m); class_addMethod(cls, NSSelectorFromString(newSel), oldImp, type); return oldImp; }
II. If you want to pass variable arguments between functions, you may need to revert to heavy hacking of the assembly. Fortunately, some smart people have already done this for you.
Use the NSInvocation class , or if that is not enough, then libffi is an even lower level.
user529758
source share