I\'m trying to save a bool value to UserDefaults from a UISwitch, and retrieve it in another view. However, I\'ve tried following multiple tutorials and stack answe
As Leo mentioned in the comments bool(forKey
returns a non-optional Bool
. If the key does not exist false
is returned.
So it's simply
boolValue = UserDefaults.standard.bool(forKey: "sound")
Calling synchronize()
as suggested in other answers is not needed. The framework updates the user defaults database periodically.