title: How to backup realm db to iCloud with Swift?
body: <p>I am trying to implement a function to backup realm db to iCloud
  <a href="https://medium.com/swlh/backup-your-applications-data-with-icloud-and-track-progress-48a00ebd2891" rel="nofollow noreferrer">https://medium.com/swlh/backup-your-applications-data-with-icloud-and-track-progress-48a00ebd2891</a></p>
  <p>I finished the setting by referring to the site above.
  And I entered the code according to the method of the site, but with no success.</p>
  <p>So I tried again like below.
  Still I can't see the file in the app in settings.
  Is there something wrong?</p>
  <p>And I am curious about how to restore to realm db in iCloud.
  Thank you</p>
  <pre><code>func uploadDatabaseToCloudDrive()
  {
  
      let fileManager = FileManager.default
  
      //let iCloudDocumentsURL = FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent(&quot;Documents&quot;, isDirectory: true)
  
      let iCloudDocumentToCheckURL = iCloudDocumentsURL.appendingPathComponent(&quot;default.realm&quot;)
      let realmArchiveURL = iCloudDocumentToCheckURL
  
      if(fileManager.fileExists(atPath: iCloudDocumentsURL.path ))
      {
          do
          {
              try fileManager.removeItem(at: realmArchiveURL)
              let realm = try! Realm()
              try! realm.writeCopy(toFile: realmArchiveURL)
  
          }catch
          {
              print(&quot;ERR&quot;)
          }
      }
      else
      {
          print(&quot;Need to store &quot;)
          let realm = try! Realm()
          try! realm.writeCopy(toFile: realmArchiveURL)
      }
  }
  </code></pre>