如何在NSUserDefaults中设置值?

时间:2013-05-15 10:41:42

标签: nsuserdefaults setvalue

我有这个:

NSMutableDictionary * responseDict = [responseString objectFromJSONString];

        NSLog(@"%@" , [responseDict objectForKey:@"loginid"]);

我想把我的“loginid”放到NSUserDefault ..

如何将loginid值放到NSUserDefault和Retrieve?

我试过这种方式但是没有正常工作

[defaults setInteger:[responseDict objectForKey:@“loginid”] forKey:@“user_id”];

请帮助

提前致谢

1 个答案:

答案 0 :(得分:0)

要输入 NSUserDefaults ,您可以执行此操作

保存:

NSString *logInId = [NSString stringWithFormat:@"%@",[responseDict objectForKey:@"loginid"]];
NSUserDefaults *preferences = [NSUserDefaults standardDefaults];
[preferences setValue:logInId forKey:@"logInId"];
[preferences synchronize];

用于检索:

NSUserDefaults *preferences = [NSUserDefaults standardDefaults];
NSString *logInIdValue = [preferences valueForKey:@"logInId"];