As documentation says, it is normally not needed to synchronise:
Waits for any pending asynchronous updates to the defaults database and returns; this method is unnecessary and shouldn't be used.
Why do you want to use synchronize and not just save on a file ?
When you are ready to quit, call a save func like this to save myArray:
func beforeQuit() {
let defaults = UserDefaults.standard
defaults.set(myArray, forKey: plistMyArrayKey)
defaults.synchronize() // this will sync with settings for App in IOS settings
}
In appDidFinishLaunching, I register defaults:
let defaults = [plistMyArrayKey: myArray] as [String : Any]
UserDefaults.standard.register(defaults: defaults)
To read defaults when loading a viewController:
override func viewDidLoad() {
super.viewDidLoad()
// 1. Read preferences
let defaults = UserDefaults.standard
myArray = defaults.integer(forKey: plistMyArrayKey)
}