Swizzle 交换2个方法的实现
#import "UIImage+image.h" #import <objc/runtime.h> @implementation UIImage (image) +(void)load //只要分类被装载到内存中 就会被调用一次 { Method ohter=class_getClassMethod([UIImage class], @selector(imageWithName:)); Method origin = class_getClassMethod([UIImage class], @selector(imageNamed:)); method_exchangeImplementations(ohter, origin); } +(UIImage*)imageWithName:(NSString*)name{ NSLog(@"====="); [UIImage imageWithName:name]; return nil; }