swizzle method
来源:互联网 发布:小说逆命淘宝 编辑:程序博客网 时间:2024/06/07 06:14
+ (void)load { [super load]; // 通过class_getInstanceMethod()函数从当前对象中的method list获取method结构体,如果是类方法就使用class_getClassMethod()函数获取。 Method fromMethod = class_getInstanceMethod([self class], @selector(viewDidLoad)); Method toMethod = class_getInstanceMethod([self class], @selector(swizzlingViewDidLoad)); /** * 我们在这里使用class_addMethod()函数对Method Swizzling做了一层验证,如果self没有实现被交换的方法,会导致失败。 * 而且self没有交换的方法实现,但是父类有这个方法,这样就会调用父类的方法,结果就不是我们想要的结果了。 * 所以我们在这里通过class_addMethod()的验证,如果self实现了这个方法,class_addMethod()函数将会返回NO,我们就可以对其进行交换了。 */ if (!class_addMethod([self class], @selector(viewDidLoad), method_getImplementation(toMethod), method_getTypeEncoding(toMethod))) { method_exchangeImplementations(fromMethod, toMethod); }}// 我们自己实现的方法,也就是和self的viewDidLoad方法进行交换的方法。- (void)swizzlingViewDidLoad { NSString *str = [NSString stringWithFormat:@"%@", self.class]; // 我们在这里加一个判断,将系统的UIViewController的对象剔除掉 if(![str containsString:@"UI"]){ NSLog(@"统计打点 : %@", self.class); } [self swizzlingViewDidLoad];}@end
0 0
- method swizzle
- swizzle method
- Objective-C 【Method Swizzle】
- Method Swizzle监听系统方法
- Method Swizzle可参考文章,黑魔法
- iOS笔记 runtime Method Swizzle 方法交换//
- Method Swizzle黑魔法,修改 ios 系统类库方法
- 如何使用Method Swizzle实现友盟统计
- iOS开发-黑魔法 method swizzle(一)
- Objective-C Runtime 解析(三)—— swizzle method
- 通过swizzle method分类已有方法扩展
- Objective-C的Method Swizzle、对象模型、消息机制、消息转发的详解
- ios swizzle
- Swift Swizzle
- linear,swizzle,tile
- linear,swizzle,tile
- 正确的Swizzle方法
- swizzle交换方法名
- Java 小知识
- 207 - PGA Tour Prize Money
- wikioi 2488 绿豆蛙的归宿(拓扑排序求期望)
- 1.害死人不偿命的(3n+1)猜想 (15)
- html嵌套规范
- swizzle method
- IDE_Webstorm11 激活
- 感知机与梯度下降算法
- 合唱队,对n个人挑出n-k个人,剩下k个人排成合唱队
- Zookeeper JavaApi 增删改查
- Android群英传——第五章实现滑动的7种方法(一二三)
- scrapy爬虫保存为csv文件的技术分析
- poj1144 割点模板
- shell中if条件字符串、数字比对,[[ ]]和[ ]区别