gpt4 book ai didi

ios - 如果我没有进行更改,为什么我需要同步 NSUserDefaults?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:46 26 4
gpt4 key购买 nike

-[NSUserDefaults synchronize:] 的文档如下:

Because this method is automatically invoked at periodic intervals, use this method only if you cannot wait for the automatic synchronization (for example, if your application is about to exit) or if you want to update the user defaults to what is on disk even though you have not made any changes.

我想知道粗体部分什么时候发生?我的意思是,如果没有对用户默认值进行任何更改,那么它会反射(reflect)磁盘上的值吗?为什么我必须调用同步来更新事件对象?我是否遗漏了一些明显的东西?

最佳答案

在 iOS 上,如果用户在“设置”应用中更新某些内容,就会发生这种情况。

在 OSX 上,如果您的首选项与另一个应用程序共享,或者如果系统范围的设置(例如,当前语言)发生变化,就会发生这种情况。但是,NSUserDefaults 从那时起已更新为自动处理此问题,并在外部发生更改时重新读取数据。

请注意,对于后一种情况,文档已过时。我已经提交了有关文档的错误报告。

关于ios - 如果我没有进行更改,为什么我需要同步 NSUserDefaults?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20866039/

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