Skip to content

Instantly share code, notes, and snippets.

@luxinyan
Created August 14, 2014 02:32
Show Gist options
  • Save luxinyan/83ab19958e45ded66083 to your computer and use it in GitHub Desktop.
Save luxinyan/83ab19958e45ded66083 to your computer and use it in GitHub Desktop.
Method Swizzle
//
// 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