扫码关注官方订阅号
Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
认证高级PHP讲师
不一定非写分类,你调下面的方法进行方法交换,位置不随便写吗?
void methodSwizzle(Class c, SEL orig, SEL newS ) { Method origMethod = class_getInstanceMethod(c, orig); Method newMethod = class_getInstanceMethod(c, newS); BOOL addSuccess = class_addMethod(c, orig, method_getImplementation(newMethod),method_getTypeEncoding(newMethod) ); if (addSuccess) { class_replaceMethod(c, newS, method_getImplementation(origMethod), method_getTypeEncoding(origMethod)); }else{ method_exchangeImplementations(origMethod, newMethod); } }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
不一定非写分类,你调下面的方法进行方法交换,位置不随便写吗?