title: Reliably getting local realm path
body: <p>I found that to get the realm path, usually this is used:</p>
  
  <p><code>Realm.Configuration.defaultConfiguration.fileURL</code></p>
  
  <p>But as far I understand, it's possible to overwrite the default configuration, when using a synced realm for example - in which case I'm not sure what this default path returns. Sometimes it's also just nil.</p>
  
  <p>The reason I need the local path is to be able to migrate the local realm to a synced realm, like described here: <a href="https://github.com/realm/realm-cocoa/issues/5381" rel="nofollow noreferrer">https://github.com/realm/realm-cocoa/issues/5381</a></p>
  
  <p>I see that these recipes use <code>Bundle.main.url</code> to get the path of the realm, but normally it seems to be stored in the <code>Documents</code> directory (am I doing something wrong?). So I defined the path like this:</p>
  
  <p><code>let documentsDirectoryUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!
  documentsDirectoryUrl.appendingPathComponent("default.realm")
  </code></p>
  
  <p>Which seems to work, but I'm not sure this is safe, as I'm assuming this will always be the default path... unless I set this path in the default configuration when the app starts.</p>
  
  <p>Any recommended approach here?</p>