how to use NSDictionary in NSUserDefault?

2019-06-09 05:58发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-06-09 06:48
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:yourData forKey:@"yourKey"];
[defaults synchronize];

id yourData = [defaults objectForKey:@"yourKey"];
查看更多
淡お忘
3楼-- · 2019-06-09 06:54
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"]; 
查看更多
登录 后发表回答