Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
View Model app restoration setup
class ViewController : UIViewController {
override func decodeRestorableState(with coder: NSCoder) {
super.decodeRestorableState(with: coder)
// force class initialization for the sake of state restoration
ViewModel.classInit
viewModel = coder.decodeObject(of: ViewModel.self, forKey: "viewModel")
}
}
@objc(ViewModel)
class ViewModel : NSObject,NSCoding {
static let classInit : () = {
// force global initialization for state restoration purposes
Entry.classInit
}()
@objc(ViewModel_Entry)
class Entry : NSObject,NSCoding {
static let classInit : () = {
// force global initialization for state restoration purposes
_ = Entry.self
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.