You need to use Singleton class to expose variables or objects to the entire project or create global variables. Create sharedInstance of TokenClass class and create property which can be accessed anywhere
in your .h
file
//token class header file
@interface TokenClass : NSObject
@property (nonatomic,strong) NSString *tokenValue;
//create static method
+ (id)sharedInstance;
in .m
file
#import "TokenClass.h"
@implementation TokenClass
#pragma mark Singleton Methods
+ (id)sharedInstance {
static TokenClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (id)init {
if (self = [super init]) {
tokenValue = [[NSString alloc] init];
}
return self;
}
@end
now in your appDelegate
#import TokenClass.h
@implementation AppDelegate
in `didFinishLaunchingWithOptions:`
[TokenClass sharedInstance] setTokenValue:@"as"];
in any class you can get value using
NSLog(@"tokenValue = %@", [[SingletonClass sharedInstance] tokenValue]);
0
solved Setter in NSString iOS