gpt4 book ai didi

ios - 如何重新设置字典的用户默认值

转载 作者:行者123 更新时间:2023-11-28 21:50:47 24 4
gpt4 key购买 nike

如何再次将用户默认设置为字典。

创建字典对象并为其设置值。

NSMutableDictionary * loginDictionary = [[NSMutableDictionary  alloc] init];
[loginDictionary setValue:@"My Address" forKey:@"ADDRESS_KEY"];
[loginDictionary setValue:@"1234567890" forKey:@"PHONE_KEY"];
[[NSUserDefaults standardUserDefaults] setObject:newDictionary forKey:@"INFO_KEY"];
[[NSUserDefaults standardUserDefaults] synchronize];

现在我评估这些字典值并分配给其他一些对象。

    NSDictionary *RetrievedDictionary = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"INFO_KEY"];
txt_Address.text = [RetrievedDictionary objectForKey:@"ADDRESS_KEY"];
txt_Mobile.text = [RetrievedDictionary objectForKey:@"PHONE_KEY"];

如何更新?
这就是我的尝试。

 [[NSUserDefaults standardUserDefaults] setObject:@"Changed Address" forKey:@"ADDRESS_KEY"];
[[NSUserDefaults standardUserDefaults] setObject:@"0987654321" forKey:@"PHONE_KEY"];
[[NSUserDefaults standardUserDefaults] synchronize];

它对我不起作用,需要你的小建议我做错了什么。@提前致谢。

最佳答案

 NSMutableDictionary* changedDictionary = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey:@"INFO_KEY"]];
[changedDictionary setObject:@"Changed Address" forKey:@"ADDRESS_KEY"];
[changedDictionary setObject:@"0987654321" forKey:@"PHONE_KEY"];
[[NSUserDefaults standardUserDefaults] setObject:changedDictionary forKey:@"INFO_KEY"];
[[NSUserDefaults standardUserDefaults] synchronize];

关于ios - 如何重新设置字典的用户默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28425903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com