iOS - Is saving to UserDefaults synchronous?

◇◆丶佛笑我妖孽 提交于 2020-05-29 12:39:09

问题


Are operations on UserDefaults synchronous? For example does the second save wait for the first save to finish?

UserDefaults.standard.set(myValue1, forKey: "myValue1")
UserDefaults.standard.set(myValue2, forKey: "myValue2")

回答1:


From apple's documentation:

At runtime, you use UserDefaults objects to read the defaults that your app uses from a user’s defaults database. UserDefaults caches the information to avoid having to open the user’s defaults database each time you need a default value. When you set a default value, it’s changed synchronously within your process, and asynchronously to persistent storage and other processes.



来源:https://stackoverflow.com/questions/50206997/ios-is-saving-to-userdefaults-synchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!