userRegistrationClass *userData = [[userRegistrationClass alloc] init];
userData.strName = [dicUserData objectForKey:@"Name"];
userData.strEmail = [dicUserData objectForKey:@"Email-ID"];
userData.strGender = [dicUserData objectForKey:@"Gender(Male Or Female)"];
userData.strUserName = [dicUserData objectForKey:@"User Name"];
userData.strPassword = [dicUserData objectForKey:@"Password"];
userData.strRePass = [dicUserData objectForKey:@"Re-Enter Password"];
userData.strBirthDte = [dicUserData objectForKey:@"Birth Day"];
userData.strMbleNum = [dicUserData objectForKey:@"Mobile Number"];
NSData *personEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:userData];
userDataStore = [NSUserDefaults standardUserDefaults];
[userDataStore setObject:personEncodedObject forKey:@"User Name"];
[userDataStore synchronize];
答案 0 :(得分:0)
如果对象存储在NSUserDefaults中,如果存储在字典中的所有键值都是NSNUmber或NSString,则无需归档对象。
NSData *personEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:userData];
NSUserDefaults *userDataStore = [NSUserDefaults standardUserDefaults];
[userDataStore setObject:personEncodedObject forKey:@"User Name"];
[userDataStore synchronize];
NSData *dataFromDefaults = [userDataStore objectForKey:@"User Name"];
NSDictionary *receivedDict = [NSKeyedUnarchiver unarchiveObjectWithData:dataFromDefaults];
NSLog(@"%@", [receivedDict description]);