title: Why is the restoration is showing all my view controllers?
body: <p>I'm working with an app that presents a series of view controllers. There is no navigation controller because when the user goes through one view, we want him to continue to the next. At some point, we need access to the camera. If the user denies access, we present an alert with a button that will take him directly to the settings of our app. When the user changes the privacy setting, as is known, the app is terminated. So, when the user relaunches the app, I want him to land exactly with the view controller that was last displayed. To this end, I made sure that all my view controllers have their restoration IDs set. I'm also returning true to the restoration delegation methods application(<em>:shouldSaveApplicationState:) and application(</em>:shouldRestoreApplicationState:). It is kinda working except that every view controller is briefly displayed before the last one appears on the screen.</p>
  
  <p>What am I missing?</p>
  
  <p>I've tried implementing application(_:viewControllerWithRestorationIdentifierPath:coder:). When I do, this method is repeatedly called initially with the restoration ID of the very first view controller in the hierarchy in the string restoration IDs array. The second time it's called, the restoration ID of the second view controller is added to the array. And it does that for every single view controller until the last one that was displayed. I tried to return the view controller matching the last restoration ID in the array but that didn't change anything. Each view controller are briefly displayed.</p>
  
  <pre><code>func application(_ application: UIApplication, viewControllerWithRestorationIdentifierPath identifierComponents: [String], coder: NSCoder) -&gt; UIViewController? {
      let mainStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
      let lastViewController = mainStoryboard.instantiateViewController(withIdentifier: identifierComponents.last!)
      return lastViewController
  }
  
  func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -&gt; Bool {
      return true
  }
  
  func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -&gt; Bool {
      return true
  }
  </code></pre>