Skip to content

Instantly share code, notes, and snippets.

@adib
Created July 29, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adib/f9e73a91ff4dabaf404e4745c12ef2cd to your computer and use it in GitHub Desktop.
Save adib/f9e73a91ff4dabaf404e4745c12ef2cd to your computer and use it in GitHub Desktop.
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