aSelector为什么在forwardInvocation:方法里没有报错?
来源:4-9 转发
慕设计0203943
2019-05-14
-(void)forwardInvocation:(NSInvocation *)anInvocation{
if (aSelector == NSSelectorFromString(@“playing”)) {
anInvocation.selector = @selector(eating);
[anInvocation invokeWithTarget:self];
}
}
2回答
-
肯定会报错的。我视频里有报错吗,我看我的代码里,是这样写的:
- (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];
}
}
012019-05-18 -
慕设计0203943
提问者
2019-05-18
嗯嗯,看到视频后面是修改过来了。我为啥诧异是因为,这么写的时候,编译器并没有报错,跑起来才显示这里有错,后面代码都改过来了。
00
相似问题