How to use a Toggle with UserDefaults in SwiftUI

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?
Answered by OOPer in 654282022
Just call set(_:forKey:) in some action closure.
Code Block
UserDefaults.standard.set(isOnState, forKey: "ToggleKeyName")

(Assuming you pass $isOnState to the isOn: of Toggle.)
Accepted Answer
Just call set(_:forKey:) in some action closure.
Code Block
UserDefaults.standard.set(isOnState, forKey: "ToggleKeyName")

(Assuming you pass $isOnState to the isOn: of Toggle.)
How to use a Toggle with UserDefaults in SwiftUI
 
 
Q