Created
April 14, 2014 19:58
-
-
Save tternes/10678320 to your computer and use it in GitHub Desktop.
ARC + Retain Hack
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
- (id)swizzled_retain | |
{ | |
NSLog(@"yes, I know"); | |
return [self swizzled_retain]; | |
} | |
+ (void)load | |
{ | |
// swizzle retain | |
Class c = [self class]; | |
SEL originalSelector = NSSelectorFromString(@"retain"); | |
SEL newSelector = @selector(swizzled_retain); | |
Method origMethod = class_getInstanceMethod(c, originalSelector); | |
Method newMethod = class_getInstanceMethod(c, newSelector); | |
if(class_addMethod(c, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) | |
class_replaceMethod(c, newSelector, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); | |
else | |
method_exchangeImplementations(origMethod, newMethod); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment