I figured out how to save the state of the switch when the state of the switch is changed. Thanks for your help on getting me there.
class SettingsCustomCell: UITableViewCell {
//...
@IBAction func switchValueChanged(_ sender: UISwitch) {
state?.settingValue = sender.isOn
let defaults = UserDefaults.standard
defaults.set(quickAddSwitch.isOn, forKey: "quickAdd")
}
}
class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource {
//...
override func viewDidLoad() {
super.viewDidLoad()
cellStates = [
SettingsState(settingLabel: "Quick Add", settingValue: (UserDefaults.standard.bool(forKey: "quickAdd")))
]
}
}
Topic:
Programming Languages
SubTopic:
Swift
Tags: