05.MethodSwizzling的问题
相关方法
看一下 RNSwizzle 的封装
//
// 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;
}方法交换不是自动的
改变不是自己的代码
命名冲突
交换方法影响了方法调用
交换的顺序
Last updated