Created
July 29, 2017 14:55
-
-
Save adib/f9e73a91ff4dabaf404e4745c12ef2cd to your computer and use it in GitHub Desktop.
View Model app restoration setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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