Skip to content

Instantly share code, notes, and snippets.

@onevcat
Created April 22, 2012 08:42
Show Gist options
  • Save onevcat/2462760 to your computer and use it in GitHub Desktop.
Save onevcat/2462760 to your computer and use it in GitHub Desktop.
dynamicMethod
void dynamicMethodIMP(id self, SEL _cmd)
{
// implementation ....
}
//该方法在OC消息转发生效前被调用
+ (BOOL) resolveInstanceMethod:(SEL)aSEL
{
if (aSEL == @selector(resolveThisMethodDynamically))
{
//向[self class]中新加入返回为void的实现,SEL名字为aSEL,实现的具体内容为dynamicMethodIMP
class_addMethod([self class], aSEL, (IMP) dynamicMethodIMP, "v@:");
return YES;
}
return [super resolveInstanceMethod:aSel];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment