I have declared some string properties on the app delegate for the purpose of global manipulation.
The trouble is the values that are written are not the same values that are being read. When I put debugging messages to print the values, it is familiar data. It almost looks like its being cached.
Code for declaration:
//globals
NSUserDefaults *options;
NSString *strUserLogin;
NSString *strTransKey;
NSString *strBizName;
NSString *strSwitchTesting;
NSString *strDate;
NSString *strTotalAmount;
NSString *strTopMessage;
NSString *strBottomMessage;
NSString *strTransType;
NSString *strMerchantName;
NSString *strCustomerEmail;
NSString *strMerchantEmail;
@property(nonatomic,retain) NSUserDefaults *options;
@property(nonatomic,retain) NSString *strUserLogin;
@property(nonatomic,retain) NSString *strTransKey;
@property(nonatomic,retain) NSString *strBizName;
@property(nonatomic,retain) NSString *strSwitchTesting;
@property(nonatomic,retain) NSString *strDate;
@property(nonatomic,retain) NSString *strTotalAmount;
@property(nonatomic,retain) NSString *strTopMessage;
@property(nonatomic,retain) NSString *strBottomMessage;
@property(nonatomic,retain) NSString *strTransType;
@property(nonatomic,retain) NSString *strMerchantName;
@property(nonatomic,retain) NSString *strCustomerEmail;
@property(nonatomic,retain) NSString *strMerchantEmail;
Load global variables with NSUserDefaults:
[NSUserDefaults resetStandardUserDefaults];
options = [NSUserDefaults standardUserDefaults];
if(options)
{
strUserLogin = [options stringForKey:@"UserLogin"];
strTransKey = [options stringForKey:@"TransKey"];
strBizName = [options stringForKey:@"BizName"];
strSwitchTesting =[options stringForKey:@"SwitchTesting"];
//str date
//total amount
strTopMessage =[options stringForKey:@"MessageTop"];
strBottomMessage =[options stringForKey:@"MessageBottom"];
//trans type
strMerchantName = [options stringForKey:@"BizName"];
//customer email
strMerchantEmail =[options stringForKey:@"MerchantEmail"];
}
else {
NSLog(@"applicationDidFinishLaunching: Error reading config file.");
}
Code to set global variables back to NSUserDefaults:
//save to disk preferences
[options setObject: txtUserLogin.text forKey:@"UserLogin"];
[options setObject: txtTransKey.text forKey:@"TransKey"];
[options setObject: txtBizName.text forKey:@"BizName"];
[options setObject: txtMerchantEmail.text forKey:@"MerchantEmail"];
[options setObject:txtMsgTop.text forKey:@"MessageTop"];
[options setObject:txtMsgBottom.text forKey:@"MessageBottom"];
if(switchTesting.on)
{
[options setObject:@"ON" forKey:@"SwitchTesting"];
}
else
{
[options setObject:@"OFF" forKey:@"SwitchTesting"];
}
//this is the magic sauce
[options synchronize];