如何从NSUserDefault打印值

时间:2014-10-31 09:15:05

标签: ios nsuserdefaults nslog

以下代码中的HI我将数据存储在nsuserdefault中,但我想查看我输入的数据,以便我如何以用户默认值打印我的数据

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];

1 个答案:

答案 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]);