I'm just studying the "message-forwarding" of Objective-C. I write a test program to verify if I can "swallow" an unrecognized selector at run-time. So I did this:
- (void) forwardInvocation: (NSInvocation *) anInvocation {
if ([anInvocation selector] == @selector(testMessage)){
NSLog(@"Unknow message");
}
return;
}
But it still throws "unrecognized selector" error at run time. After searching the resolution I know that I need to override method "methodSignatureForSelector:", so I write another proxy class called "Proxy" and the following method:
(NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
if ([Proxy instancesRespondToSelector: selector]) {
return [Proxy instanceMethodSignatureForSelector: selector];
}
return [super methodSignatureForSelector:selector];
}
But, actually, I don't want to implement such another proxy class to accomplish this method. All I want to do is that ignore this unknown selector. But If I just type this, it does not work:
(NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [super methodSignatureForSelector:selector];
}
So, I wonder there is any way that can simply "swallow" this error? (Not using exception handler, I wanna a "forwarding"-like way). Thanks!