title: Why cant I dismiss the replaykit previewController in Swift?
body: <p>I used this code in swift 2 and it worked. But now in Swift 3 the preview Controller window that pops up when the recording is finish doesn't dismiss when I press the cancel or save button. What am I doing wrong? </p>
  
  <pre><code>func stopRecording() {
  
  let sharedRecorder = RPScreenRecorder.shared()
  sharedRecorder.stopRecording(handler: { (previewController: RPPreviewViewController?, error) in
  
  if previewController != nil {
              print("stopped recording")
  
                  self.previewViewController.previewControllerDelegate = self
                  self.view?.window?.rootViewController?.present(previewController!, animated: true, completion: nil)
   }
  
  
  
  func previewControllerDidFinish(previewController: RPPreviewViewController) {
  
  previewController.dismiss(animated: true, completion: nil)
  
  }
  </code></pre>