ios运行时替换函数

来源:互联网 发布:淘宝云客服没有招聘 编辑:程序博客网 时间:2024/05/29 02:30

#include

void Swizzle(Class c, SEL origSEL, SEL newSEL)
{
Method origMethod = class_getInstanceMethod(c, origSEL);
Method newMethod = class_getInstanceMethod(c, newSEL);

if(class_addMethod(c, origSEL, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)))
class_replaceMethod(c, newSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
else
method_exchangeImplementations(origMethod, newMethod);
}

原创粉丝点击