美文网首页
实现方法交换的注意事项

实现方法交换的注意事项

作者: 陈_振 | 来源:发表于2018-06-08 15:43 被阅读0次
+ (void)load { 
    /*
     使用 dispatch_once 防止方法交换被多次调用
     */
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Method method1 = class_getInstanceMethod([self class], @selector(test1));
        Method method2 = class_getInstanceMethod([self class], @selector(test2));
        method_exchangeImplementations(method1, method2);
    });
}

相关文章

网友评论

      本文标题:实现方法交换的注意事项

      本文链接:https://www.haomeiwen.com/subject/hxsasftx.html