Search code examples
iphoneobjective-ciosiphone-sdk-3.0

How to create a NSMutable Array which can access from different view controllers


Im quite new to iphone development, I want to create a mutable array which can access and populate from different view controllers. How can I do it? If you can please give me a sample code


Solution

  • In most cases its not needed nor helpfull to use global variables. If you have to use them the easiest way is to put the array in your AppDelegate.

    You can access the Array (named array in AppDelegate here) with :

    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    
    NSArray *aArray= [appDelegate array];