I want to use a selector on an NSObject instance without the need for an implemented protocol. For example, there's a category method that should set an error property if the NSObject instance it's called on supports it. This is the code, and the code works as intended:
if ([self respondsToSelector:@selector(setError:)])
[self performSelector:@selector(setError:) withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
Undeclared selector 'setError:'
Another option would be to disable the warning with:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
You can place this line in the .m file where the warning occurs.
It works also with LLVM like this:
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector" ... your code here ... #pragma clang diagnostic pop