Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite File Location Core Data

Typically, the sqlite store file for core data apps is located in

Library>Application Support>iPhone Simulator>7.1(or whichever version you are using)>Applications>(Whichever folder contains your app)>Documents

folder, but I can't find it in IOS 8. I would assume they would just add an 8.0 folder inside the iPhone Simulator folder, but it's not there. Has anybody been able to locate it?

like image 405
enlyte Avatar asked Jun 10 '14 04:06

enlyte


People also ask

Where is core data SQLite file?

Right-click the downloaded container and choose Show Package Contents form the contextual menu. The persistent store should be located in the AppData > Library > Application Support directory. In this example you should see a SQLite database with extension . sqlite.

Is SQLite a core data?

Core Data can use SQLite as its persistent store, but the framework itself is not a database. Core Data is not a database. Core Data is a framework for managing an object graph. An object graph is nothing more than a collection of interconnected objects.

Where is SQLite database stored iOS?

The database that can be used by apps in iOS (and also used by iOS) is called SQLite, and it's a relational database. It is contained in a C-library that is embedded to the app that is about to use it. Note that it does not consist of a separate service or daemon running on the background and attached to the app.


2 Answers

I managed to locate the sqlite file, and its in this path now:

Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

(numbers and letters) stands for a folder that would be unique to your app/computer, but would look like this: 779AE2245-F8W2-57A9-8C6D-98643B1CF01A

I was able to find it by going into appDelegate.m, scrolling down to the

- (NSURL *)applicationDocumentsDirectory  

method, and NSLogging the return path, like this:

// Returns the URL to the application's Documents directory. - (NSURL *)applicationDocumentsDirectory {     NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory  inDomains:NSUserDomainMask] lastObject]);      return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];  } 

This will give you your unique path, making it easier for you, because it is tricky locating it with the 2 unnamed folders/strings of letters and numbers.

Swift 4.2:

let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) print(paths[0]) 
like image 159
enlyte Avatar answered Sep 23 '22 17:09

enlyte


None of the answers mentioned the simplest way to actually get the location of the DB file.

It doesn't even require you to modify your source code, as it's a simple run time switch in XCode.

  1. Choose Edit Scheme... next to the Run button.

    edit scheme

  2. Select Run / Arguments and add the following two options:

    -com.apple.CoreData.SQLDebug 1 -com.apple.CoreData.Logging.stderr 1 

    option

  3. Run the app, and you'll see in the logs:

    logs

like image 38
hyperknot Avatar answered Sep 21 '22 17:09

hyperknot