masumbuet Posted December 15, 2008 Share Posted December 15, 2008 Hello, I need to use some variables in multiple views. I have different .m files for different Views. I kept the variables in AppDelegate that will be used in different Views. Whenever I need any of them I create a pointer to AppDelegate using sharedApplication method, and access that variable through the AppDelegate pointer (using dot (.) operator). Is it fair? Or there is a better approach? If there is a better approach, please describe it. Is my approach creating any cyclic reference (Since, AppDelegate has a pointer to a View object which is creating pointer to AppDelegate to access to another View instance)? Let me give an example, AppDelegate.h #import "View1.h" #import "View2.h" @interface AppDelegate : NSObject <UIApplicationDelegate>{ View1* v1; View2* v2; } View2.cpp #import "AppDelegate.h" -(void) someMethod{ AppDelegate *appDel = (AppDelegate *) [[UIApplication sharedApplication] delegate]; [appDel.v1 someMethodOfView1]; } Link to comment https://www.insanelymac.com/forum/topic/141024-maintain-variables-in-iphone-development-across-multiple-views/ Share on other sites More sharing options...
Recommended Posts