aSelector为什么在forwardInvocation:方法里没有报错?

来源:4-9 转发

慕设计0203943

2019-05-14

-(void)forwardInvocation:(NSInvocation *)anInvocation{
if (aSelector == NSSelectorFromString(@“playing”)) {
anInvocation.selector = @selector(eating);
[anInvocation invokeWithTarget:self];
}

}

写回答

2回答

逆风

2019-05-16

肯定会报错的。我视频里有报错吗,我看我的代码里,是这样写的:

- (void)forwardInvocation:(NSInvocation *)anInvocation

{

    CFStudent *student = [CFStudent new];

    if (anInvocation.selector == NSSelectorFromString(@"playing")) {

        //1.改变执行的函数

        anInvocation.selector = @selector(eating);

        [anInvocation invokeWithTarget:self];

    }else if (anInvocation.selector == NSSelectorFromString(@"studying"))

    {

        //2.改变执行的目标(当然也可以同时改变执行的目标与函数

        [anInvocation invokeWithTarget:student];

    }

}

0
1
慕设计0203943
非常感谢!
2019-05-18
共1条回复

慕设计0203943

提问者

2019-05-18

嗯嗯,看到视频后面是修改过来了。我为啥诧异是因为,这么写的时候,编译器并没有报错,跑起来才显示这里有错,后面代码都改过来了。

0
0

面试跳槽提升必备 全面解析iOS中的Runtime机制

高薪职位,复杂业务需求,高性能APP,Runtime技术不可不学。

275 学习 · 48 问题

查看课程