load 和 initialize

@implementation NSObject (loadAndInitial)


+ (void)initializeAndLog {

    NSLog(@"**out- %s %@",__func__,[self class]);

    [self initializeAndLog];

}


+ (void)load{

    NSLog(@"%s",__func__);

    Method method1 = class_getClassMethod([self class], @selector(initialize));

    

    Method method2 = class_getClassMethod([self class], @selector(initializeAndLog));

    

    //交换method1和么thodIMP指针,(IMP代表了方法的具体的实现)

    

    method_exchangeImplementations(method1, method2);

}

猜你喜欢

转载自blog.csdn.net/li198847/article/details/72189106