开发者

Passing data through AppDelegate in ios

In more than one occasion i found usefull to pass data f开发者_JAVA百科rom one viewController to another using AppDelegate as bridge:

@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
    CGFloat aFloatValue;
}

This way i can get "aFloatValue" from any controller with:

 MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

and

appDelegate.aFloatValue

But i'm not sure this's a good method... what do you think about that ?


I think it depends more on the data that you are storing there and the context in which it belongs.

For example, storing the application state, such as whether a user is logged in or not, seems totally permissible. You may even have a group of settings that belong to the app that aren't editable by the user, and stored in a dictionary, and that would seem to be a good place to keep the dictionary stored.

But, lets say you had Object A and Object B which has a direct dependency on Object C, then you should probably go straight to Object C for that information, and not the Application Delegate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜