读李峰峰博客笔记之动态方法解析

2017-03-17  本文已影响6人  扑倒的柔情
/* 添加实例方法 */
resolveInstanceMethod:
/* 添加类方法 */
resolveClassMethod:
/* 完成向特定类添加特定方法实现的操作 */
class_addMethod
void dynamicMethodIMP(id self, SEL _cmd)
{
    // implementation ....
}
@implementation MyClass
+ (BOOL)resolveInstanceMethod:(SEL)aSEL
{
    if (aSEL == @selector(resolveThisMethodDynamically))
    {
          class_addMethod([self class], aSEL, (IMP) dynamicMethodIMP, "v@:");
          return YES;
    }
    return [super resolveInstanceMethod:aSEL];
}
@end
上一篇下一篇

猜你喜欢

热点阅读