Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to browse Core Data in my app running on my iPhone?

I'm working on an iPhone project that uses core data and trying to figure out a way to browse easily how data is being stored. Specifically, I am storing images in core data, and want to see how much space they're taking up, etc.

I've found an app called "Core Data Editor" that lets you browse core data on an iPhone simulator, but it's not really useful in my case since, I am storing images taken from camera. Is there a way to easily browse what is being stored on my app?

like image 609
Vlad Avatar asked Apr 14 '13 23:04

Vlad


People also ask

Where is core data saved?

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.


4 Answers

If you don't need to see this information in real time, Xcode's Organizer will allow you to download the sandbox directory of any development apps on the device:

  1. Connect the device to your Mac.
  2. Open Xcode's Organizer window to the Devices tab.
  3. In the source list, select the Applications item under your device.
  4. Pick your application from the list in the main part of the window.
  5. Use the Download button at the bottom of the window to copy the sandbox directory to your Mac.
  6. The data is downloaded in a package, so right-click it in the Finder, and select Show Package Contents.

From there, any of the many tools available to open/inspect Core Data storage or SQLite databases should work for you.

You can also use this package when running your app in the simulator or on the device to force the run into a known state. That can be tremendously helpful when debugging things like Core Data migrations or strange invalid states.

like image 128
Sixten Otto Avatar answered Nov 16 '22 02:11

Sixten Otto


To view Coredata from a device :

Plug in the device -

Start Xcode

On the top Xcode menu -

Select Window -

Select Devices -

Select your device -

Select the app -

Select the settings icon (gear shaped symbol to the right of "+ -") -

Select Download container -

Save it to a folder -

It will have an extension of ".xcappdata" -

Open FireFox

(If you dont already have it - get the FireFox SQLite Manager browser plug in) Select the SQLite Manager icon on the top right (looks like a barrel with stripes)

Select the open folder icon

change Format [SQLite DB files] to All Files

Browse to and Select your database

In addition to the tables and columns (sorry - Entities and Attributes ) you created in Coredata - you will see a few extra columns created by CoreData itself.

Hope this helps somebody. It's a bit of a bear, but worth the trouble to see your database "in the flesh"

like image 32
DontKnow Avatar answered Nov 16 '22 02:11

DontKnow


PonyDebugger is the tool you need, it lets you browse your Core Data store and many other aspects of your running application. It's free, just download, add to your app, and run the local server on your development computer that Pony Debugger talks to.

like image 23
Kendall Helmstetter Gelner Avatar answered Nov 16 '22 02:11

Kendall Helmstetter Gelner


Find the location of the sqlite database on your sim.

Then, in Terminal, use a command like this:

sqlite3 myDataBase.sqlite

At the prompt sqlite>, type

.dump

On the simulator, it will be located somewhere like:

~/Library/Application Support/iPhone Simulator/[OS version]/Applications/[appGUID]/

like image 27
RegularExpression Avatar answered Nov 16 '22 04:11

RegularExpression