Created
January 9, 2015 13:02
-
-
Save karolkozub/9e5bb07f41ad684d2581 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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