Search code examples
cocoa-touchios4suppress-warnings

Suppressing a mayNotRespond Warning in iPhone App


I have an App with a Tab Controller, which has obviously a certain number of tabs. Every ViewController in the TabController, share some informations, so I decided to move those in the AppDelegate and to synthesize everything in a NSDictionary so I can access to those using

[[[UIApplication sharedApplication] delegate] sharedInformations];

The solution works fine and I guess it's pretty good (I accept better solutions). Obviously, the compiler warns me about the fact that [[UIApplication sharedApplication] delegate] may not respond to the method sharedInformations because he didn't found the method in the protocols, but I know it will.

The question is: how do I suppress that warning?


Solution

  • You could cast it:

    [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] sharedInformations];
    

    or slightly tidier:

    MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    … = appDelegate.sharedInformation;
    

    You could also encapsulate your shared info in a Singleton class and do something like

    #import "MySharedInfo.h"
    
    MySharedInfo *sharedInfo = [MySharedInfo sharedInfo];
    // etc.