I want to know how can I use NSDictionary
in NSUserDefault
? I have to store name, points and time of user into the NSDictionary
and dictionary into the user default.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
NSDictionary *dict = [[NSDictionary alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"dict"];
[[NSUserDefaults standardUserDefaults] synchronize];
At the time of retrieval of data,
dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"dict"];
回答2:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:yourData forKey:@"yourKey"];
[defaults synchronize];
id yourData = [defaults objectForKey:@"yourKey"];