0

I would like to know how can I create a global variable type NSArray that i can use (write in/read data) from any class from y app.

At the moment i'm using NSUserDefaults, but I don't think this is the best option, because i'm saving one NSArray quite big.

Thanks.

1 Answers1

2

You can either just put it in a global variable (works the same as in C, just declare it at global scope) or, better, put it in a singleton object. Each class that wants to access it would first get the shared instance of the singleton object, which has a reference to your array. If you want the data to be persistent between runs of the application, you can still make sure to save it before quitting the app.

Community
  • 1
  • 1
Felixyz
  • 19,053
  • 14
  • 65
  • 60
  • 2
    And of course, to write data to the global variable, it should be an NSMutableArray, which is a subclass of NSArray which the original poster wanted. – harms Aug 15 '09 at 11:58