Skip to content

Instantly share code, notes, and snippets.

@karolkozub
Created January 9, 2015 13:02
Show Gist options
  • Save karolkozub/b892c156492af6d57c24 to your computer and use it in GitHub Desktop.
Save karolkozub/b892c156492af6d57c24 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSInvocation (PrivateAPI) -(void)invokeUsingIMP:(IMP)imp; @end
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@interface X : NSObject - (void)xyz; @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B @end
@implementation C - (void)abc { [super abc]; NSLog(@"-[C abc]"); } @end
@implementation X
- (BOOL)respondsToSelector:(SEL)selector {
return YES;
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [A instanceMethodSignatureForSelector:@selector(abc)];
}
- (void)forwardInvocation:(NSInvocation *)invocation {
Method method = class_getInstanceMethod([C class], @selector(abc));
[invocation invokeUsingIMP:method_getImplementation(method)];
}
@end
int main(int argc, char *argv[]) {
[[X new] xyz];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment