title: CoreData Swift : Crash : SQLite error code:14, 'unable to open database file'
body: <p>I'm using swift 2.0 with Xcode 7.
  I want to store names from a JSON file in CoreData.</p>
  
  <p>I succeed to save datas in my CoreData model, but after the value number 1272 or 1273, my app crashes.</p>
  
  <p>Here is the code :</p>
  
  <pre><code>for (key,subJson):(String, JSON) in json {
                  if let name = subJson["nom"].string {
                      print("key : \(key)")
                      self.savePerson(name)
                  }
  }
  
   func savePerson(name: String) {
      let appDelegate =
      UIApplication.sharedApplication().delegate as! AppDelegate
      let managedContext = appDelegate.managedObjectContext
      let entity =  NSEntityDescription.entityForName("Person",
          inManagedObjectContext:
          managedContext)
      let person = NSManagedObject(entity: entity!,
          insertIntoManagedObjectContext:managedContext)
      person.setValue(name, forKey: "name")
      do {
          try AppDelegate().managedObjectContext.save()
      } catch {
          fatalError("Failure to save context: \(error)")
      }
      people.append(person)
  }
  </code></pre>
  
  <p>I tried to see with a breakpoint, and here is the program at the key 1272 or 1273 :</p>
  
  <pre><code>--&gt; [savePerson()] try AppDelegate().managedObjectContext.save()
  --&gt; [AppDelegate] lazy var managedObjectContext: NSManagedObjectContext =
  --&gt; [AppDelegate][managedObjectContext] let coordinator = self.persistentStoreCoordinator
  </code></pre>
  
  <p>And here is the crash!
  I checked and the name does exist, it's not nil.
  I tried to put a kind of sleep on my code and it's not always at the same moment. Do you think this is a question of speed ?</p>
  
  <p>Else, do you know why ?</p>
  
  <p>The log is :</p>
  
  <pre><code>CoreData: error: (14) I/O error for database at     /.../.../.../SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file'
  2015-09-22 23:59:59.774 testAlamofire2[8765:351886] CoreData: error: Encountered exception I/O error for database at /.../.../.../SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file' with userInfo {
  NSFilePath = "/.../.../.../.../SingleViewCoreData.sqlite";
  NSSQLiteErrorDomain = 14;
  } while checking table name from store: &lt;NSSQLiteConnection: 0x7f8e2d677ee0&gt;
  2015-09-22 23:59:59.779 testAlamofire2[8765:351886] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///.../.../.../.../SingleViewCoreData.sqlite options:(null) ... returned error Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at .../.../.../SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file'} with userInfo dictionary {
  NSSQLiteErrorDomain = 14;
  NSUnderlyingException = "I/O error for database at /.../.../...SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file'";
  }
  2015-09-22 23:59:59.780 testAlamofire2[8765:351886] Unresolved error Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo={NSLocalizedDescription=Failed to initialize the application's saved data, NSLocalizedFailureReason=There was an error creating or loading the application's saved data., NSUnderlyingError=0x7f8e2d6772d0 {Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at /.../.../.../SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file'}}}, [NSLocalizedDescription: Failed to initialize the application's saved data, NSLocalizedFailureReason: There was an error creating or loading the application's saved data., NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=256 "(null)" UserInfo={NSSQLiteErrorDomain=14, NSUnderlyingException=I/O error for database at /.../.../.../.../SingleViewCoreData.sqlite.  SQLite error code:14, 'unable to open database file'}]
  </code></pre>
  
  <p>EDIT : </p>
  
  <p>I found this <a href="https://developer.apple.com/library/mac/qa/qa1809/_index.html#//apple_ref/doc/uid/DTS40014115" rel="nofollow">page</a>, I don't know if it helps. (old)</p>