I have an iOS application with several controllers, each with their own xib files.
How do I set a global variable with scope that spans all controllers? Should I use NSUserDefaults and retrieve data for each view every time?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NSUserDefaultsare for things that require persistance, i.e. you are planning on storing them between app starts. For temporary variables, consider using a singleton instance, such as theMySingletonclass illustrated in this answer: https://stackoverflow.com/a/145164/108574 .When you have this class, put your temporary variables as
propertyof this class for easy access. And when you need to access it, just call[MySingleton sharedSingleton].variable.Also check here: http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html for more information.