iOS - 同步保存到 UserDefaults 吗?
iOS - Is saving to UserDefaults synchronous?
对 UserDefaults 的操作是同步的吗?例如,第二次保存是否等待第一次保存完成?
UserDefaults.standard.set(myValue1, forKey: "myValue1")
UserDefaults.standard.set(myValue2, forKey: "myValue2")
来自苹果的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.
对 UserDefaults 的操作是同步的吗?例如,第二次保存是否等待第一次保存完成?
UserDefaults.standard.set(myValue1, forKey: "myValue1")
UserDefaults.standard.set(myValue2, forKey: "myValue2")
来自苹果的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.