I am a newbie in swift using Xcode trying to write a small checklist app. After I check/uncheck the checkbox and exit the app, the state just disappears next time when I reopen it next time. I am wondering how can I save the current state of NSButton as default so that next time when I open the app, it will show up the same state when I closed it. I tried below practice:
Set default value:
@IBAction func Check1(_ sender: NSButton) {
UserDefaults.standard.set(Check1.state, forKey:"Check1status")
}
Read default value:
override var representedObject: Any? {
didSet {
Check1.state = UserDefaults.standard.bool(forKey:"Check1status")
}
}
However I received error message:"Cannot assign value of type 'Bool' to type 'NSControl.StateValue'"
How can I fix this error? Thanks.