I have a singleton class which I intend to share throughout my whole application. It looks like this:
.m
@implementation PersonalGlobal
@synthesize firstName;
@synthesize lastName;
@synthesize SSN;
@synthesize customerNo;
@synthesize email;
@synthesize address;
@synthesize city;
@synthesize postalCode;
@synthesize telNo;
@synthesize mobileNo;
#pragma mark Singleton Methods
+ (id)sharedPersonal {
static PersonalGlobal *sharedPersonalGlobal = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedPersonalGlobal = [[self alloc] init];
});
return sharedPersonalGlobal;
}
- (void)dealloc {
[super dealloc];
// Should never be called
}
@end
.h
#import <foundation/Foundation.h>
@interface PersonalGlobal : NSObject {
NSString *firstName;
NSString *lastName;
NSString *SSN;
NSString *customerNo;
NSString *email;
NSString *address;
NSString *city;
NSString *postalCode;
NSString *telNo;
NSString *mobileNo;
}
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;
@property (nonatomic, retain) NSString *SSN;
@property (nonatomic, retain) NSString *customerNo;
@property (nonatomic, retain) NSString *email;
@property (nonatomic, retain) NSString *address;
@property (nonatomic, retain) NSString *city;
@property (nonatomic, retain) NSString *postalCode;
@property (nonatomic, retain) NSString *telNo;
@property (nonatomic, retain) NSString *mobileNo;
+ (id)sharedPersonal;
@end
In the code I save strings to it like so:
PersonalGlobal *sharedPersonal = [PersonalGlobal sharedPersonal];
sharedPersonal.firstName = @"Some string";
But when I change view and try to access the string like this:
PersonalGlobal *sharedPersonal = [PersonalGlobal sharedPersonal];
//Setting some textfield
sometextfield.text = sharedPersonal.firstName;
I get nothing. I have done a #import "PersonalGlobal.h"
in all the files.
Can i commit the changes in any way to the singleton class?
Can anyone see what I am doing wrong here? Thanks!