2

I use Core Data in my application, and I want to know that where is the SQLite file located.

I have already read the relative post and I didn't find the answer.

Mikolaj
  • 802
  • 10
  • 18
Jeff Leung
  • 61
  • 2
  • 9

1 Answers1

2

During initialization of the Core Data Stack you decide, where the database file will be located. The standard place is the documents directory. See Apple Developer - Initializing the Core Data Stack.

You will find there the following code

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let docURL = urls[urls.endIndex-1]
/* The directory the application uses to store the Core Data store file.
This code uses a file named "DataModel.sqlite" in the application's documents directory. 
*/
let storeURL = docURL.URLByAppendingPathComponent("DataModel.sqlite")

The storeURL is the file URL you are looking for (and docURL is just a directory without a file name included).

You can also find this directory using NSSearchPathForDirectoriesInDomains

NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).last! as String

Check IOS 8 Store sqlite File Location Core Data for other ideas like find used in Terminal for example.

Community
  • 1
  • 1
Mikolaj
  • 802
  • 10
  • 18