Hello, 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.
From stackoverflow
-
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.
harms : 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.
0 comments:
Post a Comment