JSPATCH
(https://www.cnblogs.com/graveliang/p/5809519.html)
( https://www.cnblogs.com/zhang-chi/p/6179791.html)
( https://www.cnblogs.com/fengmin/p/5880443.html)
( http://www.reibang.com/p/7e2efff789e2)
1.檢查是否動(dòng)態(tài)添加 如果動(dòng)態(tài)添加 執(zhí)行添加的 沒(méi)有進(jìn)入下一步
void play (id self, SEL _cmd)
{
NSLog(@"實(shí)現(xiàn)被轉(zhuǎn)移到這里");
}
+ (BOOL)resolveInstanceMethod:(SEL)sel{
if (sel == @selector(play)){
class_addMethod([self class], sel,(IMP)play, "v@:");
return YES;
}
return [super resolveInstanceMethod:sel];
}
```
二,如果沒(méi)有動(dòng)態(tài),就看看有沒(méi)有指定其他的類實(shí)現(xiàn)
- (id)forwardingTargetForSelector:(SEL)aSelector OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0){
return [[Guitar alloc] init];
}
三,如果還沒(méi)有,那么就進(jìn)行獲取簽名,如果獲取到 NSMethodSignature
methodSignatureForSelector
消息:
最后給他他 如果沒(méi)有就報(bào)錯(cuò)
- (void)forwardInvocation:(NSInvocation *)anInvocation