如何在NSUserDefault中使用NSDictionary?

时间:2021-07-23 13:50:21

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.

我想知道如何在NSUserDefault中使用NSDictionary?我必须将用户的名称,点和时间存储到用户默认的NSDictionary和字典中。

2 个解决方案

#1


4  

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


2  

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:yourData forKey:@"yourKey"];
[defaults synchronize];

id yourData = [defaults objectForKey:@"yourKey"];

#1


4  

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


2  

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:yourData forKey:@"yourKey"];
[defaults synchronize];

id yourData = [defaults objectForKey:@"yourKey"];