Skip to content

Instantly share code, notes, and snippets.

@karolkozub
Created January 9, 2015 13:02
Show Gist options
  • Select an option

  • Save karolkozub/9e5bb07f41ad684d2581 to your computer and use it in GitHub Desktop.

Select an option

Save karolkozub/9e5bb07f41ad684d2581 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface A : NSObject - (void)abc; @end
@interface B : A @end
@interface C : B @end
@implementation A - (void)abc { NSLog(@"-[A abc]"); } @end
@implementation B @end
@implementation C - (void)abc { [super abc]; NSLog(@"-[C abc]"); } @end
@interface X : NSObject - (void)xyz; @end
@implementation X
+ (void)load {
Method method = class_getInstanceMethod([C class], @selector(abc));
IMP imp = method_getImplementation(method);
const char *typeEncoding = method_getTypeEncoding(method);
class_addMethod(self, @selector(xyz), imp, typeEncoding);
}
@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