1. 程式人生 > >load 和 initialize

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);

}