简体   繁体   English

NSUserDefaults中的新键/值

[英]New key/value in NSUserDefaults

I have a simple question that I'm not able to find the answer to. 我有一个简单的问题,无法找到答案。

Can I add a new key/value to my userdefault just by 我可以通过以下方式向我的用户默认值添加新的键/值吗?

[userdefaults setBool:YES forKey:@"onSwitch"]

Or must it be in the defaults.plist first? 还是必须先在defaults.plist中?

Yes you can add a new key/value to your user-defaults. 是的,您可以向用户默认值添加新的键/值。

If it exists it will overwrite it, otherwise a new key/value pair will be created. 如果存在,它将覆盖它,否则将创建一个新的键/值对。

如果该值不存在,它将创建并设置它。

Yes, you can. 是的你可以。 :) :)

Make sure to add this code when you add any key/value in user defaults: 在用户默认值中添加任何键/值时,请确保添加以下代码:

[[NSUserDefaults standardUserDefaults] synchronize];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM