How can I ignore the warning?


I believe it was in this section that we put this code into HomepwnerItemCell.m showImage: method

if ([[self controller] respondsToSelector:newSelector]) {
         // Ignore warning for this line - may or may not appear, doesn't matter
         [[self controller] performSelector:newSelector

This is the place where the warning started showing up. I’m into the next chapter now, but this warning continues to be there. I’m not sure if I was supposed to ignore it forever or not. But the fact that the comment said it might or might not show up to me means that it might be possible to let Xcode know to ignore this “problem.” Am I wrong in thinking that? If not, then how do I silence the warning?



What is the warning saying exactly?


PerformSelector may cause a leak because its selector is unknown.

If I remember correctly, that’s because the selector message is being sent to another class…the one that’s controlling the cell.


I have used the following code to provoke the warning message that you mentioned.
It is only coming out when you have the Automatic Reference Counting turned on in the build settings. If you handle the object ownership manually, by turning off ARC and retaining/releasing objects when required, the warning message disappears.

//  main.m

#import <Foundation/Foundation.h>

@interface IT: NSObject
- (void)junk:(id)object;

@implementation IT
- (void)junk:(id)object

void Perform (SEL theSelector, IT *it);

int main (int argc, const char * argv[])
    IT *it = [[IT alloc] init];
    SEL theSelector = @selector (junk:);
    Perform(theSelector, it);
    return 0;

void Perform (SEL theSelector, IT *it)
    NSLog (@"%s", __PRETTY_FUNCTION__);

    [it performSelector:theSelector withObject:nil];


I thought there might be a way to manually ignore a single warning message. Maybe in future versions of xcode this will become available.

Thanks for the replies.


I think you can ignore the warning.
The fact that you call respondsToSelector prevents your code from a leak I guess.
But the warning will continue to show up because the compiler can’t know if the selector exists and how the called method will manage memory.

Found this on stackoverflow

[quote]#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Warc-performSelector-leaks”
//the code causing warning
#pragma clang diagnostic pop[/quote]
Should disable the warning :slight_smile: