OC中的方法调用,其实都是转化成objc_msgSend函数调用
1.信息发送
E082EBCE-4892-403A-B1B0-CAA04E51E1FE.png2.动态方法解析
/// 对象消息解析
+ (BOOL)resolveInstanceMethod:(SEL)sel
动态方法解析如果解析成功就回到第一阶段消息发送
/// 类消息解析
+ (BOOL)resolveClassMethod:(SEL)sel
###3.信息转发
- (id)forwardingTargetForSelector:(SEL)aSelector
{
if (aSelector == @selector(test)) {
return nil;
}
return [super forwardingTargetForSelector:aSelector];
}
// 方法签名:返回值烈性。参数类型
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if (aSelector == @selector(test)) {
return [NSMethodSignature signatureWithObjCTypes:"v16@0:8"];
}
return [super methodSignatureForSelector:aSelector];
}
// NSInvocation 封装了一个函数调用。包括:方法调用者,方法,方法参数
// anInvocation.target
// anInvocation.selector
// [anInvocation getArgument:NULL atIndex:0];
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation invokeWithTarget:[[Cat alloc] init]];
}
- (void)doesNotRecognizeSelector:(SEL)aSelector
{
![E5DD7433-667D-44FD-A15E-E74BC69F7F0B.png](https://img.haomeiwen.com/i9717104/b2dd436214f66807.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
用途:消息转发收集Bug
网友评论