I'm trying to save the state of some switches and restore it when the app launches again but when I wrote this :
override func encodeRestorableState(with coder: NSCoder) {
super.encodeRestorableState(with: coder)
coder.encode(Int32(self.runSwitch1.state.rawValue), forKey: CodingKey.Protocol)
}
I got this error :
Cannot convert value of type 'CodingKey.Protocol.Type' to expected argument type 'String'
What should I do ?
If you mean't was restoring state between app switches provide a unique key against the type to be encoded
//Decode later when state restore
And restore switch state by
Use CoreData or other db based framework to sustain states even after app is closed. Or you can do it using userdefaults
and in your controller