In general, you want to avoid using global variables. If you need access to data that should be shared, there are two common approaches.
Put the values ββin AppDelegate.
If you have only one or two common values, AppDelegate is an easy way to post shared content.
Access to AppDelegate can be obtained from your controllers as such:
FooApp* appDelegate = (FooApp*)[[UIApplication sharedApplication] delegate];
Where FooApp
is the name of your application class.
Create a singleton class.
Contaminating your AppDelegate with many common values ββis not ideal and / or if you want these values ββto be saved from session to session, creating a Singleton class that is supported by NSUserDefaults
is another way to exchange values ββbetween instances.
source share