Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式
认证高级PHP讲师
You don’t have to write categories. You can adjust the following method to exchange methods. Why don’t you just write the position?
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); } }
You don’t have to write categories. You can adjust the following method to exchange methods. Why don’t you just write the position?