I’ve tried making a global array that can add and remove items across all view controllers. I’ve used the
App delegate *app …. Method and then allocated an array like this app. Mutable array = nsmutable array alloc init
However I can’t get it to be implemented globally.
I’ve tried making a global array that can add and remove items across all
Share
What you need is a static variable and a mean to access it. In Objc, the usual way to do that is with a singleton.
Then you access your array with:
You may also go the C route with something like this, in any .m file put:
And in any .h file:
Then you can just call
mySharedArray()from any code that includes the .h file where it’s declared.NOTE: Either those approach are not thread safe, if you want a thread safe global array, you will have to do some locking.