to prevent warning from "PerformSelect may cause a leak because its selector is unknown"

22,482

Just use this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:arguments];
#pragma clang diagnostic pop
Share:
22,482
Admin
Author by

Admin

Updated on May 30, 2020

Comments

  • Admin
    Admin about 4 years

    Possible Duplicate:
    performSelector may cause a leak because its selector is unknown

    I did a NSDictionary to convert my input(NSString) to selector. The "selector map" is looked as follows :

    [self setCmdSelectorMap:[NSDictionary dictionaryWithObjectsAndKeys: 
                             [NSValue valueWithPointer:@selector(doOpenBrowserByString:)], @"openBrowser",
                             [NSValue valueWithPointer:@selector(syncData:)], @"sync",
                             [NSValue valueWithPointer:@selector(getCachedString:)], @"getCachedString",
                             nil]];
    

    When I try to fetch one of these selector and perform it by follows, it cause a warning :

    sel = [[_cmdMap objectForKey:command] pointerValue];
    NSLog(@"selector determined : %@", NSStringFromSelector(sel));
    [self performSelector:sel withObject:arguments];
    

    The warning says : PerformSelector may cause a leak because its selector is unknown. Is there any way to prevent this warning from occurring? or is there any "safer" way to perform such an action?

    Thanks guys :)