Well, if i understand your question correctly...
I'm using this model for a long time (original):
You need to create a generic data container class AppDataObject
. This is an ancestor class for a data container object that you would actually use to hold your application's global variables.
At init time, You need to add code to the app delegate that create an empty data container object.
After that, you need to create a dirt simple protocol, AppDelegateProtocol
. This protocol only lists one method, -theAppDataObject.
That method lets you ask the app delegate for it's data object.
And create a subclass of the AppDataObject
that actually holds data for a real app. This is where you put the information that you want to share between objects.
Using a protocol
means that the only things the objects in your app need to include are the AppDelegateProtocol
and the header for your subclass of the app data object. You don't have to #include
the header of your app delegate, which makes for good separation between the different objects in your app.
You can download project, ViewControllerDataSharing
, that uses the above method to share information between view controllers. The project uses a navigation controller, and has a root view controller and a second view controller. Each view controller has a UITextView
and a slider. The app uses an AppDataObject
to pass the value of these fields between view controllers.
This method was described by DuncanC - iphonedevsdk forums. This method really saved me a lot of time.