I tried to create a singleton to set and get a string between different views:
globalVar.h:
@interface globalVar : NSObject
{
NSString *storeID;
}
+ (globalVar *)sharedInstance;
@property (nonatomic, copy) NSString *storeID;
@end
globalVar.m:
#import "globalVar.h"
@implementation globalVar
@synthesize storeID;
+ (globalVar *)sharedInstance
{
static globalVar *myInstance = nil;
if (nil == myInstance) {
myInstance = [[[self class] alloc] init];
}
return myInstance;
}
@end
Now how do I actually use the string? Say I want to set it to “asdf” in one view and load the “asdf” in another view.
To set it, do something like:
And to use it: