I’m fairly new to objective-c.
I’m trying to develop mostly experimental projects for a future development of a game app.
I would like to have suggestions on what I should use for the following purpose.
I’m trying to keep a group of objects somewhere (lets say something like an Array) in objective-c. I want that group of objects to be available everywhere in my application (different functions etc.) That group of objects has to be edit ready so NSArray (I guess) is out of the question? must be.
I’m struggling with concepts and still looking for the right way to do such a thing, tried to force some global arrays but I think that wasn’t good practice.
Any help would be highly appreciated, thanks. (Please be kind enough to provide some further explanation on why I should use this -your suggestion- instead of something else. In that way you will help me grasp the idea better).
If it’s a group of objects that needs to be shared throughout the entire application, and you want to shy away from global variables, then I think you have one good option:
By creating and storing the collection (which should be an
NSMutableArray, an editable version ofNSArray) in your application delegate, it can be accessible everywhere:And then you can access it anywhere, like so:
Keep in mind that if you’re going to be accessing/editing this array on any background thread (or using GCD) then you’ll have to ensure that the access is properly synchronized. (Are you planning on doing so?)