I'm receiving a warning
PerformSelector may cause a leak because its selector is unknown
In the code:
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
//this line the warning
[delegate performSelector: selector
withObject: arg
withObject: err];
}
else
{
//this line the warning
[delegate performSelector: selector
withObject: err];
}
}
else
{
NSLog(@"Missed Method");
}
}
Header:
@interface Topscore : UIViewController <NSObject> {
//
}
This is a warning generated by the compiler because -Wundeclared-selector was used while compiling and automatic reference counting (ARC) is enabled. This can be, in general, safely ignored, as it's obvious that the selector in the variable named "selector" is unknown at compile time, as it will have its value assigned at runtime.
Your
if ... respondsToSelector: selector
won't work because yourselector
is just the name of the method. For your case you need to checkand for the other case just for
method:
.Anyway, you can supress the warning like this:
Easiest way is adding this macro to your pch File. Or .m file..
You could add -Wno-arc-performSelector-leaks for
WARNING_CFLAGS
in theBuild Settings
.Found the solution here
You can also use objc_msgSend instead of performSelector, as described here.