Last active
January 1, 2016 17:59
-
-
Save emarashliev/8180518 to your computer and use it in GitHub Desktop.
Override Methods with Categories
This file contains 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 "A.h" | |
#import <objc/runtime.h> | |
@implementation A (EatApple) | |
- (void)printAppleOverride | |
{ | |
[self printAppleOverride]; | |
NSLog(@"Eat that Apple"); | |
} | |
+ (void)load | |
{ | |
method_exchangeImplementations(class_getInstanceMethod(self, @selector(printApple)), class_getInstanceMethod(self, @selector(printAppleOverride))); | |
} | |
@end |
This file contains 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
@implementation A | |
- (void)printApple | |
{ | |
NSLog(@"The original Apple"); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment