access an integer and string globally in iphone?

access an integer and string globally in iphone?

i want to access a integer and a string from a class to all the other classes? what is the best way to do it? i want to increase the values any where in the program and then want to update them in the class declared....

any idea how to achieve this???

Exception/Error handling in Objective-C (iPhone app)


How to show “Done” button on iPhone number pad
Here's a question (and good answers) around singletons.. How do you duplicate a file in XCode? You could also use the app delegate, as frankodwyer suggested, and access it from anywhere using:. Unit testing an iPhone static library with XCode 3
id delegate = [[UIApplication sharedApplication] delegate]; 
For ease of use and type safety I use a category like this:. Image getting pixelated when used as part of an animation in iPhone animation
// put his in your delegate header file @interface UIApplication(MyAppAdditions) + (MyAppDelegate*)sharedDelegate; @end  // put his in your delegate implementation file @implementation UIApplication(MyAppAdditions) + (MyAppDelegate*)sharedDelegate {     return (MyAppDelegate*)[[self sharedApplication] delegate]; } @end 
Now you must access your app delegate from everywhere: [UIApplication sharedDelegate]. UITableView Animation Headache
iPhone OpenGL ES incorrect alpha blendingDoes a NSURLConnection retain its delegate?


You could make the integer and string properties of your app delegate and pass references to the delegate around to your views. I did any thing like this myself, though to be honest it is a pain and also a little error prone to make the app delegate available to all the views.. Or (and this is probably better), you could declare a singleton class (google the singleton pattern) as one of your data classes, and have your integer/string be properties of that. Then you could access the receive ters/setters of your singleton from anywhere in your program. You will need to take extra care if you have multiple threads however,.

38 out of 100 based on 18 user ratings 218 reviews