title: Stopping NSPrintOperation From Crashing Application
body: <p>I have the following lines of code to print the <code>webView</code> content.</p>
  
  <pre><code>let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
  let printOpts: NSDictionary = [NSPrintJobDisposition: NSPrintSaveJob, NSPrintSaveJob: directoryURL, NSPrintScalingFactor: 2.0]
  let printInfo = NSPrintInfo(dictionary: printOpts as! [String : AnyObject])
  
  printInfo.horizontalPagination = .autoPagination
  printInfo.verticalPagination = .autoPagination
  
  let printOperation = NSPrintOperation(view: webView.mainFrame.frameView, printInfo: printInfo)
  printOperation.printPanel.options = [.showsOrientation, .showsPaperSize, .showsPreview, .showsPageSetupAccessory, .showsScaling, .showsPrintSelection]
  printOperation.run()
  </code></pre>
  
  <p>The problem is that it sometimes causes the application to crash when the user interacts with the print operation panel.</p>
  
  <p><a href="https://i.stack.imgur.com/mxvQU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mxvQU.png" alt="enter image description here"></a></p>
  
  <p>If I just click on the cancel button, the application can crash.  And if I try to set a different scale rate, it can sometimes crash.  I don't know why the application will crash.  It's always the last line.  What am I doing wrong?  Thanks.</p>
  
  <p><a href="https://i.stack.imgur.com/0jz7T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0jz7T.png" alt="enter image description here"></a></p>