access an integer and string globally in iphone?
iphone, objective-c, xcode
Solution
Here's a question (and good answers) about singletons.
You could also use the app delegate, as frankodwyer suggested, and access it from anywhere using:
id delegate = [[UIApplication sharedApplication] delegate];
For ease of use and type safety I use a category like this:
// 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 can access your app delegate from everywhere: `[UIApplication sharedDelegate]`
Problem
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???