Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check what is stored in my Core Data Database?

Tags:

ios

core-data

I am making an app that relies on Core Data. I am able to enter data into a text field and store it.

But I need to know if the data is being stored.

I am trying to make a detailView to my tableView and I am not getting any results. Now I am wondering is that because I am doing something wrong with my code, or is the data nto being stored properly.

How can I see what is stored in the app's CoreData database?

like image 347
jwknz Avatar asked Apr 20 '12 02:04

jwknz


People also ask

Where is Data stored in Core Data?

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. It is possible that you don't see the persistent store in the Application Support directory.

What database does Core Data use?

The persistence part of Core Data is backed by SQLite, which is a relational database.


2 Answers

Here is my solution(works on iOS 9):

I use an automator/bash script that open the database in sqllitebrowser. the script finds the latest installed app in the simulator. Instructions:

  1. Install DB Browser for SQLite (http://sqlitebrowser.org/)
  2. Create new workflow in Apple Automator.
  3. Drag "Run Shell script block" and paste this code:
cd ~/Library/Developer/CoreSimulator/Devices/ cd `ls -t | head -n 1`/data/Containers/Data/Application  cd `ls -t | head -n 1`/Documents open -a DB\ Browser\ for\ SQLite ./YOUR_DATABASE_NAME.sqlite 

enter image description here

  1. (Optional) Convert this workflow to application, save it and drag it to your dock. To refresh the database just click on the app icon.
like image 107
Zaster Avatar answered Sep 21 '22 12:09

Zaster


Swift 4, 5

Add this line in AppDelegate >> didFinishLaunchingWithOptions function:

print("Documents Directory: ", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last ?? "Not Found!") 

Your modelName.sqlite file will be there.

You can open it with any SQLite browser tools like http://sqlitebrowser.org/ that is free.

like image 33
Vahid Avatar answered Sep 21 '22 12:09

Vahid