I am looking for a solution to my situation. My app is as followed:
On VC1 there is a textfield and button. User types a name. Then click on a button. This button open V
here is how you can define singleton class that is called AppShareData : AppShareData.h
@interface AppSharedData : NSObject
+(AppSharedData*)sharedInstance ;
@property (nonatomic) BOOL sharedBoolVariable ;
@end
AppShareData.m:
@implementation AppSharedData
@synthesize sharedBoolVariable;
+(AppSharedData *) sharedInstance
{
static AppSharedData *_sharedInstance = nil;
static dispatch_once_t Token;
dispatch_once(&Token, ^{
_sharedInstance = [[AppSharedData alloc]init];
});
return _sharedInstance;
}
@end
and then if you want to edit or set the value of the variable in any class i would do the following :
-(void)editMethod
{
AppSharedData * dataObject = [AppSharedData sharedInstance] ;
dataObject = YES ;
}
and if i want to retrieve the value of the variable in any class i do the following :
-(void)retrieveMethod
{
AppSharedData * dataObject = [AppSharedData sharedInstance] ;
BOOL someVariableInMyClass = [dataObject sharedBoolVariable] ;
}