I am looking for the most optimal way to store and read variables globally across all my classes. I understand I could use a ‘singleton’ however I wasn’t sure whether this was the best method for storing my variables or how to go about doing this exactly?
Share
I use singletons and here is how I do it:
Create a new class, for the demonstration here we will name it
MyDataModel. In MyDataModel.h do the following:Now in the MyDataModel.m do:
Now in any class you want to use this singleton you have to
#importthis class and here is how to use the variables:I hope this clarifies things for you.