I want to do something a little hacky.
When we try and call a method on a class where isn’t defined we usually get an error, e.g.
// We get a undefined selector callback
[myClass someUndefinedMethod];
I want to add something into MyClass that catches all these undefined method calls and deals with it. Is this possible?
I want something like this, but which will intercept all method calls:
@implementation MyClass
- (void) performSelector(SEL):selector {
// Check if the method exists
if (![self respondsToSelector:selector]) {
// Handle unimplemeted selector
NSLog(@"No method called %@", selector);
}
// Otherwise proced as normal
else {
[super performSelector:selector];
}
}
@end
Why not just override the
doesNotRecognizeSelector:method on NSObject (assuming you’re inheriting from it, which you should be)?