Q:

Storing global objects in IOS apps?

I am working on an ios app in which in the first viewcontroller the user is asked to provide its name gender age and native language. Then i will use those objects during the whole app. So what is the best way to store the objects so they are easilly accessible from all classes? 

A:

Use NSUserDefaults. Really simple to use and can be accessed from anywhere in the application. 
You should use it to store user preferences. It can store simple data types as well as complex objects and even array, dictionaries. To store any key would be as simple as,
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:firstName forKey:@"firstName"];

And reading it back,
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *firstName = [defaults objectForKey:@"firstName"];

Note: User defaults are stored in a plist file and gets loaded each time application launches. So be careful to not write too much information into it. Otherwise the application loading time increases and if it goes beyond watchdog timer interval, the app will receive SIGKILL and crash. 
But in your case, for storing user settings you can go ahead and use this.
Hope that helps!

A:

Create singleton class say MySingletonClass and define your variable. 
you can access your variable from any class by singleton object.
// MySingleton.h
@interface MySingletonClass : NSObject

{
    //your global variable here
}

// set property for your variable

+ (MySingletonClass*)sharedInstance; // method for getting object of this singleton class

// In MySingleton.m
//synthesize property for your global variable

+ (MySingletonClass*)sharedInstance
{ 

  if ( !sharedInstance)
  {
      sharedInstance = [[UIController alloc] init];

   }
 return sharedInstance;
}

Now in other class you can access this variable.
follow this code to access variable define in MySingletonClass
MySingletonClass* sharedInstance = [MySingletonClass sharedInstance]; // get object of MySingletonClass
sharedInstance.yourVariable; // now you can access variable defined in MySingletonClass by this object.

You can also definde global variable in AppDelegate (not recommended ).

