title: UIDocument not saving to file despite indicating success
body: <p>I'm trying to open, modify, and save a file in iCloud Drive using <code>UIDocument</code>. When I call <code>save(to:for:completionHandler:)</code> with the file location and using <code>.forOverwriting</code> for the <code>UIDocumentSaveOperation</code>, it completes with a status of <code>success = true</code>. However, the iCloud file (as seen in both desktop and iOS file browser) does not update, and when reopening the file, the changes are not shown. I've verified that <code>contents(forType:)</code> returns the correct (modified) file contents when saving.</p>
  
  <p>(Note: I've already looked at <a href="https://stackoverflow.com/questions/22332165/uidocument-not-saving">this question</a>, but it wasn't very helpful )</p>
  
  <p>Here are the relevant sections of code:</p>
  
  <p><strong>MainViewController.swift:</strong></p>
  
  <pre><code>var saveFile: SBDocument?
  
  @IBAction func bbiOpen_pressed(_ sender: UIBarButtonItem) {
  
      if saveFile == nil {
          let importMenu = UIDocumentMenuViewController(documentTypes: self.UTIs, in: .import)
          importMenu.delegate = self
          importMenu.popoverPresentationController?.barButtonItem = bbiOpen
          self.present(importMenu, animated: true, completion: nil)
      } else {
          willClose()
      }
  
  }
  
  func willClose(_ action: UIAlertAction?) {
      if saveFile!.hasUnsavedChanges {
          dlgYesNoCancel(self, title: "Save Changes?", message: "Would you like to save the changes to your document before closing?", onYes: doSaveAndClose, onNo: doClose, onCancel: nil)
      } else {
          doSaveAndClose(action)
      }
  }
  
  func doSaveAndClose(_ action: UIAlertAction?) {
      saveFile?.save(to: saveFileURL!, for: .forOverwriting, completionHandler: { Void in
          self.saveFile?.close(completionHandler: self.didClose)
      })
  }
  
  func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
      saveFile = SBDocument(fileURL: url)
      saveFile!.open(completionHandler: { success in self.finishOpen(didCompleteSuccessfully: success) })
  }
  
  func finishOpen(didCompleteSuccessfully result: Bool) {
      if result {
          print(saveFile!.localizedName)
          saveFileURL = saveFile!.fileURL
          saveFileName = saveFile!.localizedName
          self.navTitleBar.prompt = saveFileName
          bbiOpen.title = NSLocalizedString("titleClose", comment: "Close")
          bbiOpen.style = .plain
      } else {
          saveFile = nil
      }
  }
  
  @IBAction func bbiSave_pressed(_ sender: UIBarButtonItem) {
      self.saveFile!.save(to: self.saveFileURL!, for: .forOverwriting, completionHandler: self.didSave)
  }
  
  func didSave(_ success: Bool) {
      guard success else {
          print("Error saving soundboard file to \(String(describing: saveFileURL))")
          return
      }
      print("File saved successfully")        
  }
  </code></pre>
  
  <p><strong>SBDocument.swift:</strong></p>
  
  <pre><code>class SBDocument: UIDocument {
      override var fileType: String? { get { return "com.whitehatenterprises.SoundBoardFX.sbd" } }
      override var savingFileType: String? { get { return "com.whitehatenterprises.SoundBoardFX.sbd" } }
  
      override init(fileURL url: URL) {
          super.init(fileURL: url)
      }
  
      override func contents(forType typeName: String) throws -&gt; Any {
          let arr = NSArray(array: SoundEffects)
          let data: NSData = NSKeyedArchiver.archivedData(withRootObject: arr) as NSData
          return data
      }
  }
  </code></pre>
  
  <p><strong>Update:</strong>
  I really need help with this, and I've tried everything I can think of to fix this. Any assistance you could give me would be greatly appreciated.</p>