How to view data stored in Core Data?
Asked Answered
F

12

51

I'm creating a Core Data model for my application. I would like to be able to look inside it to see what I have stored in there.

Is there an easier way than searching for the backing store (mine should be SQLite) and reading it from there? Doesn't seem very Apple-esque.

Franchot answered 15/2, 2010 at 18:32 Comment(2)
Possible duplicate of Is there a good Core Data browsing tool out there?Odilia
On iOS 10+ you can see use the solution in this answer : https://mcmap.net/q/235092/-how-can-i-check-what-is-stored-in-my-core-data-databaseHomo
D
62

Once your app has run in the simulator and created the persistent store file, you can find the file in your app's Documents directory.

Your app data will be folder inside (~ is your home directory):

~/Library/Developer/CoreSimulator/<device>

In versions prior to XCode 6, the path was:

~/Library/Application Support/iPhone Simulator/User/Applications/

I sort by "Date Modified" to find the app that I just built.

For viewing a SQLite file, check out Base and/or Core Data Editor.

Dentilingual answered 15/2, 2010 at 18:34 Comment(7)
In particular, Core Data Editor presents your database in a reasonably accessible manner.Reareace
Is there a free way to do this?Become
@Become Base has a free trial (fifteen minutes at a time), but even more free would be to pop open Terminal, navigate to the same directory, and run the SQLite3 app. Inside the app's Documents directory, find the <Model>.sqlite file, and run it with "sqlite3 <Model>.sqlite", replacing Model with the real filename.Shondrashone
Firefox also has an SQLLite viewing plugin that is pretty good for free. Buy Base though.Faythe
Is there any way to do this on an app that has run on a device and not in the simulator?Undersurface
@Undersurface Yes. Go to Xcode Organizer > your device > your app > Download "Data files in Sandbox". Ctrl-click the .xcappdata file and select "Show Package Contents". AppData > Documents > Open *.sqliteDentilingual
actually since Xcode 6 it seams to be somewhere inside of: ~/Library/Developer/CoreSimulatorWinker
B
22

You can also use FireFox's Add-on tool SQLite Manager (FREE). I use it and it works well.

Batts answered 21/4, 2010 at 17:44 Comment(2)
Awesome answer. Once you've download the Plugin and figured out how to launch it, you can print your database location using print(NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)). Then, in the Plugin, when you want to open the database, you'll need to have enabled hidden folders in Finder.Alban
unfortunately addons.mozilla.org/en-US/firefox/addon/sqlite-manager is not compatible with the latest firefox.Puto
I
20

If you are using iOS 10 & Swift get it into your AppDelegate.swift:

  let container = NSPersistentContainer(name: "***")
  print(container.persistentStoreDescriptions.first?.url)

Then you'll see something like that:

Optional(file:///Users/<SomeUser>/Library/Developer/CoreSimulator/Devices/956F0003-5DA4-4588-97C1-A9A83767F341/data/Containers/Data/Application/9765FDE1-6971-4706-987B-96FBD3F462BF/Library/Application%20Support/***.sqlite)
Indomitable answered 24/10, 2016 at 8:18 Comment(0)
F
11

You can try a little free tool called CoreDataPro. Pretty nice. Here

Freestyle answered 28/8, 2013 at 15:1 Comment(0)
P
5

Update to this thread, The iphone simulator location has been moved to a different location in Xcode7 and Xcode8. It is now in:

~/Library/Developer/CoreSimulator/...

where ~ is your home directory.

Any of the previous solutions will still work, but you won't be able to find the correct folder if you use the previous links.

Paleography answered 2/2, 2017 at 19:25 Comment(0)
B
5

Core Data Lab is a dedicated Core Data viewer that offers everything to view and analyze the Core Data database of your app, like automatic search for databases, data change tracker, simulator browser, a predicate editor, data editor, a built-in web and image content viewer, and much more.

Info page: https://betamagic.nl/products/coredatalab.html

Free 14-trial: https://betamagic.nl/downloads/Core%20Data%20Lab%20Trial.zip

Diclaimer: I'm the creator of this tool.

Brogue answered 14/1, 2020 at 10:1 Comment(3)
Spent an hour trying other tools. This is exactly what I would expect, great tool!Dealing
Just tested with an iOS simulator - UI looked promising, but app crashed within 1m consistently when selecting several tables (it is a small DB).Saul
@Saul Please contact [email protected] so we can fix the cause of the crash. Thank you!Brogue
C
2

Also try sqlite database browser. its free and reflects that fact. very useful though!

cheers.bo

Celestyn answered 19/7, 2011 at 1:21 Comment(0)
W
2

I created a macOS app to browse your Core Data content. It hides Core Data implementation as you see when you use a SQLite browser. Also you can list all your latest run apps and simulators, with this you can easily find the app you are looking for. More info here:

http://www.microedition.biz/simMagnifier

It has other features like access Simulator's folders such as Documents, Application Support, etc. You can check the content of NSUserDefaults too.

The app is not free sorry! but at least you have a 7 days trial.

Whiles answered 23/12, 2016 at 3:0 Comment(1)
work like charm!Laveralavergne
J
1

Here is the full path, apparently it changed since gerry3's answer

~/Library/Application Support/iPhone Simulator/<Simulator>/Applications/<ApplicationID>/Documents/<NAME>.sqlite

So a correct path would like this:

~/Library/Application Support/iPhone Simulator/7.1-64/Applications/C1F3C2E5-987A-4DF7-91EF-955AE6E52621/Documents/TestApp.sqlite
Joinery answered 29/4, 2014 at 14:18 Comment(0)
W
1

3 Easy Steps

  1. install liya application, its free, Size 3.1 MB, so installs in 1 minute.
    Link https://itunes.apple.com/us/app/liya/id455484422?mt=12.

  2. Open Finder, Press "Ctrl + G" OR "CMD + Ctrl + G", Paste ~/Library/Developer/
    In Developer Folder, search for your Core Data model name (eg. MyProjectModel).

  3. Open MyProjectModel.d file Or 'MyProjectModel.sqlite' using liya. In liya, select a table, Click on "Run SQL Command".

Done.

Winfrid answered 19/7, 2018 at 22:19 Comment(0)
A
0

The easiest and fastest way for me at the moment is

  1. Install This SIMSMI

Next ..

  1. Install This SQLite Browser

'SIMSIM' will take you to the ios app files, you will see something like this:-

enter image description here

Next ..

  1. Take your files that located inside

/Library/Application Support

(drag&drop) to the SQLite Browser

Enjoy ;)

Authenticate answered 11/10, 2023 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.