Covers iOS app state preservation and restoration with extra emphasis on NSCoding. WWCD 2012 session 208 glosses over some of the fine details of how NSCoding works. Understanding this foundation better helps in understanding state preservation and restoration.
Automating Google Workspace (GWS) & more with Apps Script
iOS State Preservation and Restoration
1. iOS State Preservation and
Restoration
Robert Brown
Twitter: @robby_brown
app.net: @robert_brown
2. What is State Restoration?
Restores your app where the user left it
Makes your apps appear as if they never terminated
Lets users seamlessly get back to what they want
7. Restoration Identifiers
Each view controller you want to restore must define a
restoration identifier
Restoration identifiers make up a restoration ID path
Restoration paths must be unique
Example: /TabBarController/AboutViewController
15. UIDataSourceModelAssociation
Many views will automatically restore their state
UITableView and UICollectionView need some extra
help to restore your visible and selected cells
UIDataSourceModel association provides a mapping of
cells to model objects
This is NOT intended to be used to persist data
20. Gotchas
Must use proper UIViewController containment
Restoration identifier paths must be unique
For a view controller to be restored, it must have a path
to the root view controller
Manually terminating the app will delete the state
21. Gotchas
Restore only minimal state in
+viewControllerWithRestorationIdentifierPath:
If a view controller that was persisted is not restored,
the app delegate is given a chance to restore it
Testing state restoration isn’t straightforward
Press home button, then have Xcode kill the app
22. Gotchas
Restoration classes must conform to the
UIViewControllerRestoration protocol
Restoration classes aren’t necessary when using
UIStoryboard
23. Gotchas
If you change your view controller hierarchy, make sure
you don’t restore from an older state
If your app crashes during restoration, the state data is
thrown out
24. Want to Learn More?
WWDC Session 208
Archives and Serializations Programming Guide
iOS App Programming Guide