I need to create an object for example NSString
and let other classes get/set the value for it.
thx. for help :)
I need to create an object for example NSString
and let other classes get/set the value for it.
thx. for help :)
The easiest way to do this is to attach the value as a property to a singleton instance of some class. One singleton instance that already exists in your application is the application delegate. So, just add an NSString
property to your application delegate and you can access it from any class in your app (as long as you #import
your application delegate).
In your application delegate:
@property(nonatomic, strong) NSString* someString;
In your other classes:
[self doSomethingWithAString:((YourAppDelegateClass*)[[UIApplication sharedApplication] delegate]).someString];
Create a Singleton/Shared class.
@implementation SINGLETON
static SINGLETON *instance = nil;
+(SINGLETON*)sharedInstance{
@synchronized(self) {
if (instance == nil) {
instance = [[SINGLETON alloc] init];
}
return instance;
}
}
EDIT:
This will come handy... Objective-C Singleton problem. Object recognized in one class but not another