开发者

Suppressing a mayNotRespond Warning in iPhone App

开发者 https://www.devze.com 2023-02-22 16:23 出处:网络
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

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

[[[UIApplic开发者_JAVA技巧ation 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?


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消