问题
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"];
来源:https://stackoverflow.com/questions/6173939/how-to-use-nsdictionary-in-nsuserdefault