iOS开发 Method Swizzling 可以调换两个方法

来源:互联网 发布:淘宝宝贝销量查询工具 编辑:程序博客网 时间:2024/05/20 23:37

例子

#import <objc/runtime.h>


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
//    Method method1 = class_getInstanceMethod([XMGPerson class], @selector(run));
//    Method method2 = class_getInstanceMethod([XMGPerson class], @selector(study));
//    method_exchangeImplementations(method1, method2);
//    
//    
//    XMGPerson *p = [[XMGPerson alloc] init];
//    [p run];
//    
//    [p study];

0 0