title: How do I permanently save a file to iCloud using FileManager using Swift?
body: <p>When I save a file to iCloud, when the app shuts down, the file is not there anymore.</p>
  
  <p>Here is my code before the app shuts down with the print results in comments beside the print statements:</p>
  
  <pre><code>    FileManager.default.createFile(atPath: saveToURL.path, contents: dataImage, attributes: nil)
  
      print("??? \(saveToURL.path) imagePicker file exists=", FileManager.default.fileExists(atPath: saveToURL.path)) // ??? /private/var/mobile/Library/Mobile Documents/iCloud~us~gnolaum~TrialVisionBoard/12BF0AB3-C0EB-4D13-A37E-7853839225BD.jpg cellForRowAt file exists= false
  </code></pre>
  
  <p>Notice that when the code checks if the file exists after the file is created, it checks out true.</p>
  
  <p>Following is the code after the app starts again:</p>
  
  <pre><code>     print("??? \(mediaURL.path) cellForRowAt file exists=", FileManager.default.fileExists(atPath: mediaURL.path)) // ??? /private/var/mobile/Library/Mobile Documents/iCloud~us~gnolaum~TrialVisionBoard/12BF0AB3-C0EB-4D13-A37E-7853839225BD.jpg cellForRowAt file exists= false
  </code></pre>
  
  <p>Notice that the url path is identical to the path before the app shut down but the file after the app restarts does not exist.</p>
  
  <p>I suspect I need to set the correct attributes for the file I create. Anyone know what exactly I need to do to get the file to stay saved in iCloud?</p>
  
  <p>ADDITIONAL CONTENT:</p>
  
  <p>I noticed that I don't have this problem when I run the project on iPhone 5 Simulator. The problem occurs when I run the project on my iPhone 5 device.</p>