title: Swift 3 - Dismissing view controller after async job
body: <p>I am using Swift 3, Xcode 8.2.</p>
  
  <p>I have a view controller on which there is a button.  When the button is pressed, it runs the <code>buttonPressed</code> function below.  It kicks off an asynchronous job which takes a few seconds to complete during which a spinning gear activity indicator pops up.  Once the job is finished, I want the activity indicator to dismiss and the view controller to dismiss as well to the VC that it originally came from.</p>
  
  <pre><code>func buttonPressed() {
  
      // Set up some stuff here
      ...
  
      // this code block here is to asynchronously run the processing job
      // while the activity indicator gear spins
      self.displaySpinningGear()
      DispatchQueue.main.async {
          self.doSomeJobProcessing()
      }
      self.dismiss(animated: true, completion: nil)
  
      // also dismiss the camera view
      self.presentingViewController?.dismiss(animated: true, completion: nil) // error here
  }
  </code></pre>
  
  <p>However, I get an error on that last statement: </p>
  
  <blockquote>
    <p>[Assert] Trying to dismiss the presentation controller while
    transitioning already.
    (&lt;_UIAlertControllerAlertPresentationController: 0x109e3b190>)
    2017-03-03 21:37:56.833899 EOB-Reader[27710:6869686] [Assert]
    transitionViewForCurrentTransition is not set, presentation controller
    was dismissed during the presentation?
    (&lt;_UIAlertControllerAlertPresentationController: 0x109e3b190>)</p>
  </blockquote>
  
  <p>Any help would be greatly appreciated.</p>