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