1

So, there are other postings on how to get rid of this warning, but none seem to work on a SEL parameter -- so this is not a duplicate.

So, I'm creating a printer interface, and in the interest of modularity I created a method to which you provide a callback, as shown below.

This works great, my printer class does not seem to need to know about my client UI class, except, i get the subject warning "PerformSelector may cause a leak because its selector is unknown".

I know there are other ways to get callback action (eg a delegate), but is there a way to use this pattern (callback as method parameter) and not cause this warning?

Thanks!

* IN MY PRINTER CLASS *

+(void) SearchPrinters:(id)onfinish_callback_target withSelector:    (SEL)onfinish_callback_sel
{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// perform the search
        dispatch_sync(dispatch_get_main_queue(), ^{
            [onfinish_callback_target performSelector:onfinish_callback_sel];  // <-- WARNING HERE
        });
    });
}

* IN MY CLIENT UI CLASS *

-(void) OnTouch_Search
{
    // pushed button, prepare for search and call

    [cPrinterInterface SearchPrinters:self withSelector:@selector(SearchCallback)];
}

-(void) SearchCallback
{
// do stuff when done
}
Chris
  • 617
  • 1
  • 10
  • 24
  • Have you tried wrapping it in `NSSelectorFromString` ( https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/#//apple_ref/c/func/NSSelectorFromString )? This may just silence – Losiowaty Jan 12 '16 at 18:03
  • 1
    Have you tried [this solution](http://stackoverflow.com/questions/11895287/performselector-arc-warning/11895530#11895530)? – rob mayoff Jan 12 '16 at 18:09
  • 2
    The best idea, of course, is to not use the target-action pattern. Blocks or delegate+protocol makes for a far better interface anyway. – Avi Jan 12 '16 at 18:19
  • 1
    Possible duplicate of [performSelector may cause a leak because its selector is unknown](http://stackoverflow.com/questions/7017281/performselector-may-cause-a-leak-because-its-selector-is-unknown) – Cristik Jan 12 '16 at 18:46

0 Answers0