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 prop
While the correct answer likely lies in informing Xcode through imports or registering the selector that such a selector exists, in my case I was missing a semi-colon. Make sure before you "fix" the error that perhaps, the error is correct and your code isn't. I found the error in Apple's MVCNetworking sample, for instance.
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.
Update:
It works also with LLVM like this:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
... your code here ...
#pragma clang diagnostic pop
I got that message to go away by #include'ing the file with the method. Nothing else was used from that file.
A really comfortable macro to put in your .pch
or Common.h
or wherever you want:
#define SUPPRESS_UNDECLARED_SELECTOR_LEAK_WARNING(code) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wundeclared-selector"\"") \
code; \
_Pragma("clang diagnostic pop") \
It's an edit of this question for similar issue...
I think this is because for some odd reason the selector isn't registered with the runtime.
Try registering the selector via sel_registerName():
SEL setErrorSelector = sel_registerName("setError:");
if([self respondsToSelector:setErrorSelector]) {
[self performSelector:setErrorSelector withObject:[NSError errorWithDomain:@"SomeDomain" code:1 userInfo:nil]];
}
I realise I'm a bit late to this thread but for completeness, you can globally turn off this warning using the target build settings.
In section, 'Apple LLVM warnings - Objective-C', change:
Undeclared Selector - NO