Skip to content

Instantly share code, notes, and snippets.

@emarashliev
Last active January 1, 2016 17:59
Show Gist options
  • Save emarashliev/8180518 to your computer and use it in GitHub Desktop.
Save emarashliev/8180518 to your computer and use it in GitHub Desktop.
Override Methods with Categories
#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
@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