NSUserDefault 可以被覆盖吗?
有一个 NSUserDefault ,其值:
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"aValue"];
它可以被另一个值覆盖吗?如:
[[NSUserDefaults standardUserDefaults] setObject:@"2" forKey:@"aValue"];
如果是,可能有什么优点和缺点?
There's a NSUserDefault with Value:
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"aValue"];
Can it be overwritten by the another value? As:
[[NSUserDefaults standardUserDefaults] setObject:@"2" forKey:@"aValue"];
If yes what may be the pros and cons?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,该值将被覆盖。 NSUserDefaults 用于存储信息,即使您的应用程序关闭后也是如此。
当您想要(例如在游戏中)增加用户已完成的关卡数量时,通常需要这样做。
我看到的唯一缺点是,如果您忘记了某个键的名称,您可能会在无意时意外地覆盖已有的值。
Yes, the value will be overwritten. NSUserDefaults is used to store information even after your app is closed.
This is often desired when you want to (for example in a game) increase the number of levels the user has completed.
The only disadvantage I see is that if you forget the name of a key, you might accidentally write over the value already there when you didn't intend to.