To set values, use the below code.
YourSingletonClass *sharedManager = [YourtSingletonClass sharedManager];
sharedManager.nameString =@"name";
sharedManager.emailString =@"name@domain.com";
For getting values, use the below code
YourSingletonClass *sharedManager = [YourtSingletonClass sharedManager];
NSString *nameVal=sharedManager.nameString;
NSString *emailVal=sharedManager.emailString;
/////YourSingletonClass.h class
#import
@interface YourSingletonClass : NSObject{
NSString *nameString;
NSString *emailString;
}
@property (nonatomic, strong) NSString *nameString;
@property (nonatomic, strong) NSString *emailString;
+ (id)sharedManager;
@end
/////YourSingletonClass.m class
#import "YourSingletonClass.h"
@implementation YourSingletonClass
@synthesize nameString;
@synthesize emailString;
+ (id)sharedManager {
static YourSingletonClass *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
self.nameString = @"";
self.emailString = @"";
}
return self;
}
- (void)dealloc {
// Should never be called, but just here for clarity really.
}
@end
No comments:
Post a Comment