Created
August 14, 2014 02:32
-
-
Save luxinyan/83ab19958e45ded66083 to your computer and use it in GitHub Desktop.
Method Swizzle
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
// | |
// RNSwizzle.m | |
// MethodSwizzle | |
#import "RNSwizzle.h" | |
#import <objc/runtime.h> | |
@implementation NSObject (RNSwizzle) | |
+ (IMP)swizzleSelector:(SEL)origSelector | |
withIMP:(IMP)newIMP { | |
Class class = [self class]; | |
Method origMethod = class_getInstanceMethod(class, | |
origSelector); | |
IMP origIMP = method_getImplementation(origMethod); | |
if(!class_addMethod(self, origSelector, newIMP, | |
method_getTypeEncoding(origMethod))) | |
{ | |
method_setImplementation(origMethod, newIMP); | |
} | |
return origIMP; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment