Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App State Restoration - Swift Bangalore #9

Swift India
September 22, 2018

App State Restoration - Swift Bangalore #9

Swift India

September 22, 2018
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. What are we gonna discuss? • What is State Restoration?

    • How does it help us? • How does it work internally? • How to integrate?
  2. Let us INTEGRATE …. !! • App Delegate • View

    Controllers • Save Data & Restore Data
  3. View Controllers • Provide with Restoration Identifier • Confirm to

    UIStateRestoring Protocol • Provide a Restoration Class (Optional) • Confirm to UIViewControllerRestoration Protocol (Optional) • Encode and Decode relevant Data
  4. • If RestorationIdentifier is not set, UIKit skips restoration for

    the view controller & subsequent controllers in hierarchy • Storyboard handles providing restoration class and reference to controller for restoration • If implemented without storyboard, provide restoration id, restoration class and controllers instance.
  5. What to save? What not to save? • Data necessary

    to recreate the view controller • Primary key of records • UI states e.g. Slider value, Button Selection • Its not user defaults nor data • Saved state can be lost • If data is a preference, don’t store it in state restoration archive • Don’t convert to data and encode
  6. Control Flow App Launches Load initial UI First App initialisation

    Does your app supports state restoration ? Get the ViewControllers Decode saved objects Finish App restoration Finish App Initialisation Run App NO YES UIKit appDelegate: applicationWillFinishLaunching: appDelegate: shouldRestoreApplicationState: viewController: withRestorationIdentifierPath viewController: decodeRestorableState appDelegate: didDecodeRestorableState
  7. What we discussed? • What is State Restoration? • What

    are its benefits? • How to integrate within App? • Do’s and Don’ts • Control Flow