Hi all,
This' is a strange problem I'm facing. The following code which I used to save my values to nsuserdefaults was working fine.. saving and retrieving all the values but it's totally driving me nuts now. It's not saving any values and the retrieved values are seen invalid. I'm using encoding and decoding to save my custom object named companyObject. Not a single values is stored.
-(void)saveCustomObject
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *companyArray = [[NSMutableArray alloc]init];
for(Company *companyObj in companyObjectsArray)
{
[companyArray addObject: [NSKeyedArchiver archivedDataWithRootObject:companyObj]];
}
[defaults setObject:companyArray forKey:@"companyData"];
[defaults setObject:userCompanyInfo.sessionkey forKey:@"sessionkey"];
[defaults setObject:userCompanyInfo.deviceid forKey:@"deviceid"];
[defaults setObject:userCompanyInfo.userid forKey:@"userid"];
[defaults setObject:userCompanyInfo.service_type forKey:@"service_type"];
[defaults setObject:userCompanyInfo.isduallogin forKey:@"isduallogin"];
[defaults setObject:userCompanyInfo.securitycode forKey:@"securitycode"];
[defaults synchronize];
}
-(void)loadCustomObject
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *companies = [NSMutableArray array];
NSArray *oldCompanies = [[NSUserDefaults standardUserDefaults] arrayForKey:@"companyData"];
if( companies )
{
for( NSData *data in oldCompanies )
{
Company* companyObj = (Company*) [NSKeyedUnarchiver unarchiveObjectWithData:data];
[companies addObject:companyObj];
}
}
NSString *sessionKey = [defaults stringForKey:@"sessionkey"];
NSString *deviceId = [defaults stringForKey:@"deviceid"];
NSString *userId = [defaults stringForKey:@"userid"];
NSString *service_type = [defaults stringForKey:@"service_type"];
NSString *isduallogin = [defaults stringForKey:@"isduallogin"];
NSString *securitycode = [defaults stringForKey:@"securitycode"];
}
Can anybody please help?
Between I'm running this on simulator. All the values [i.e. strings here] are in place, only not getting inserted. Also I'm getting this line printed in console if I do Print Description of variables in which I'm storing the values: A syntax error in expression, near `variable)'.
EDIT: This application when this part was running, was actually running on MAC pc but now I'm running it on macbook. Can this create this problem?
Thanx in advance.