Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Is saving to UserDefaults synchronous?

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")
like image 379
Micro Avatar asked May 07 '18 04:05

Micro


1 Answers

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.

like image 161
M Reza Avatar answered Sep 24 '22 14:09

M Reza