Unable to open a realm at path
<p>I am trying to use a bundled realm file without success. I know that my realm file was copied successfully to my application’s Directory but I ca not read it. </p>

<blockquote>
  <p>fatal error: 'try!' expression unexpectedly raised an error: "Unable
  to open a realm at path
  '/Users/…/Library/Developer/CoreSimulator/Devices/…/data/Containers/Data/Application/…/Documents/default-v1.realm'.
  Please use a path where your app has read-write permissions."</p>
</blockquote>

<pre><code> func fullPathToFileInAppDocumentsDir(fileName: String) -&gt; String {

        let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,NSSearchPathDomainMask.UserDomainMask,true)

        let documentsDirectory = paths[0] as NSString

        let fullPathToTheFile = documentsDirectory.stringByAppendingPathComponent(fileName)

        return fullPathToTheFile
    }
</code></pre>

<p>In <code>didFinishLaunchingWithOptions</code>:</p>

<pre><code>  let fileInDocuments = fullPathToFileInAppDocumentsDir("default-v1.realm")

        if !NSFileManager.defaultManager().fileExistsAtPath(fileInDocuments) {

            let bundle = NSBundle.mainBundle()

            let fileInBundle = bundle.pathForResource("default-v1", ofType: "realm")

            let fileManager = NSFileManager.defaultManager()

            do {
                try fileManager.copyItemAtPath(fileInBundle!, toPath: fileInDocuments)
            } catch {  print(error)  }
        }
</code></pre>

<p>And setting the configuration used for the default Realm:</p>

<pre><code>var config = Realm.Configuration()
config.path = fileInDocuments

Realm.Configuration.defaultConfiguration = config

let realm = try! Realm(configuration: config)  // It fails here!!! :-)
</code></pre>

<p>As the documentation suggests, I have tried as well to open it directly from the bundle path by setting <code>readOnly</code> to <code>true</code> on the <code>Realm.Configuration</code> object. I am not sure if this is something related to Realm or if I am overlooking something with the file system…. I have also tried to store the file in the Library folder.</p>

<pre><code>Realm 0.97.0
Xcode Version 7.1.1
</code></pre>