美文网首页
实例方法的消息转发

实例方法的消息转发

作者: Jean_Lina | 来源:发表于2022-05-15 21:49 被阅读0次
    - (int)sheep:(int)time;
    
    #pragma mark 实例方法的消息转发
    + (BOOL)resolveInstanceMethod:(SEL)sel {
        if (sel == @selector(sheep:)) {
            NSLog(@"+ resolveInstanceMethod");
            return YES;
        }
        return [super resolveInstanceMethod:sel];
    }
    - (id)forwardingTargetForSelector:(SEL)aSelector {
        if (aSelector == @selector(sheep:)) {
            NSLog(@"- forwardingTargetForSelector");
            return nil;
        }
        return [super forwardingTargetForSelector:aSelector];
    }
    - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
        if (aSelector == @selector(sheep:)) {
            NSLog(@"- methodSignatureForSelector");
            return [NSMethodSignature signatureWithObjCTypes:"i@:i"];
        }
        return [super methodSignatureForSelector:aSelector];
    }
    - (void)forwardInvocation:(NSInvocation *)anInvocation {
        if (anInvocation.selector == @selector(sheep:)) {
            NSLog(@"- forwardInvocation");
            int retValue;
            [anInvocation getReturnValue:&retValue];
            int time;
            [anInvocation getArgument:&time atIndex:2];
            NSLog(@"retValue %d", retValue);
            NSLog(@"time %d", time);
        }
    }
    

    相关文章

      网友评论

          本文标题:实例方法的消息转发

          本文链接:https://www.haomeiwen.com/subject/gfqtpltx.html