1、定义C函数:
void dynamicMethodIMP(id self, SEL _cmd)
{
NSLog(@"蜗牛也疯狂");
}
2、重写函数+(BOOL)resolveInstanceMethod:(SEL)sel
+(BOOL)resolveInstanceMethod:(SEL)sel
{
class_addMethod([self class], sel, (IMP)dynamicMethodIMP, "v@:");
return [super resolveInstanceMethod:sel];
}
3、使用:
SEL select = NSSelectorFromString(@"resolveThisMethodDynamically");
[class resolveInstanceMethod:select];
[[class instance] performSelector:select];