How do I call a method that I previously saved using the code below:
SEL sel = @selector(someMethod:param:);
Method myMethod = class_getInstanceMethod([SomeClass class], sel);
As you may imagine, calling [SomeClass someMethod] is not going to work because, later, I swizzle the original method.
You need to typecast the pointer to the proper function type, keeping in mind that methods have two implicit arguments, self and _cmd. From Apple’s runtime docs:
(Edit)
Keep in mind that the Method type is a struct, and in the ObjC2 runtime, it’s opaque, so you don’t have direct access to its members – you’ll need to use
method_getImplementation(myMethod)to get an IMP that you can typecast like above.