From the course: iOS Development: Architecture
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
App state restoration
- [Instructor] The decodeRestorableState(with coder decodes the previously saved state information and restores the ViewController to that state. I have to call super.decodeRestorableState(with coder also here. Then we try to decode the object for the editedText key using NSCoder objects decode method. It should be a String. If we find the valid String, we assign it to the textView.text property. Alright, now we can set break points in the encodeRestorableState and the decodeRestorableState that will let us to track when the system calls these methods. Now, let's run the demo. I'm gonna change the default text to say State Restoration Test. Next, I hit the Home button and the app goes to the background. The encodeRestorableState(with coder gets called to preserve the state of our view controller. Now, I'm gonna queue up the app by double-tapping the Home button and swiping out the app. Let's restart the app from Xcode and see what happens. Well, the app state wasn't restored. Instead…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.