Search code examples
iossdkwarningspragma

Remove warning when using newer SDK version method


I'm using a method that is available since the version 5.0 of the iOS SDK. Of course before calling it, I'm checking whether or not the class has the method (in other word it is checking the iOS version that is running) :

if ([UITabBar instancesRespondToSelector:@selector(setSelectedImageTintColor:)]) {
    [myTabBarController.tabBar setSelectedImageTintColor :TINT_COLOR_IMAGES];
}

This works fine. However I'm getting a warning that I want to remove, but I didn't find anything that could deal with it. The warning is :

warning: ‘UITabBar’ may not respond to ‘-setSelectedImageTintColor:’
warning: (Messages without a matching method signature
warning: will be assumed to return ‘id’ and accept
warning: ‘...’ as arguments.)

As I don't want to remove all warning in my project (removing the option -Wall), I tried this #pragma :

#pragma GCC diagnostic ignored "-Wundeclared-selector"
[...] my method containing call to setSelectedImageTintColor
#pragma GCC diagnostic warning "-Wundeclared-selector"

But this didn't work, even when I replaced "Wundeclared-selector" by "Wall" which means that the #pragma has no effect, and maybe I need to activate something in my makefile.

Any idea ?

Thanks


Solution

  • to remove the warning change this

     [myTabBarController.tabBar setSelectedImageTintColor :TINT_COLOR_IMAGES];
    

    to

     [myTabBarController.tabBar performSelector:@selector(setSelectedImageTintColor:) withObject:TINT_COLOR_IMAGES];
    

    This will remove the warning