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

 

posted @ 2016-08-17 21:02  谢小锋  阅读(278)  评论(0编辑  收藏  举报