Created
December 13, 2018 16:37
-
-
Save henkvanderspek/28cb165fda71e92dd1b4aed346c3dcee to your computer and use it in GitHub Desktop.
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 <objc/runtime.h> | |
#import <Foundation/Foundation.h> | |
@implementation NSObject (BadAssSwizzle) | |
+ (void)load { | |
SEL originalSelector = @selector(init); | |
SEL overrideSelector = @selector(myInit); | |
Method originalMethod = class_getInstanceMethod(self, originalSelector); | |
Method overrideMethod = class_getInstanceMethod(self, overrideSelector); | |
if (class_addMethod(self, originalSelector, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) { | |
class_replaceMethod(self, overrideSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod)); | |
} else { | |
method_exchangeImplementations(originalMethod, overrideMethod); | |
} | |
} | |
- (void)myInit { | |
NSLog(@"%@", [self class]); | |
[self myInit]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment