Hi, In my App, I have a SettingsView, where I want to make a toggle. I want to store the information if the toggle is set true or false in the UserDefaults. How can I do that?
How to use a Toggle with UserDefaults in SwiftUI
Just call set(_:forKey:) in some action closure.
(Assuming you pass $isOnState to the isOn: of Toggle.)
Code Block UserDefaults.standard.set(isOnState, forKey: "ToggleKeyName")
(Assuming you pass $isOnState to the isOn: of Toggle.)