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.

Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
Frank
  • 1,426
  • 1
  • 14
  • 14
  • Possible duplicate of [Is there a good Core Data browsing tool out there?](http://stackoverflow.com/questions/1609683/is-there-a-good-core-data-browsing-tool-out-there) – swiftBoy Dec 24 '15 at 07:26
  • On iOS 10+ you can see use the solution in this answer : https://stackoverflow.com/a/43406516/468724 – Inder Kumar Rathore Jul 06 '17 at 06:07

11 Answers11

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.

pojo
  • 5,892
  • 9
  • 35
  • 47
gerry3
  • 21,420
  • 9
  • 66
  • 74
  • 3
    In particular, Core Data Editor presents your database in a reasonably accessible manner. – Brad Larson Feb 15 '10 at 18:53
  • 3
    Is there a free way to do this? – barfoon Mar 18 '10 at 23:31
  • @barfoon 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 .sqlite file, and run it with "sqlite3 .sqlite", replacing Model with the real filename. – eddieroger Sep 22 '11 at 11:57
  • 3
    Firefox also has an SQLLite viewing plugin that is pretty good for free. Buy Base though. – Kendall Helmstetter Gelner Oct 03 '11 at 05:40
  • Is there any way to do this on an app that has run on a device and not in the simulator? – Jonathan Dec 18 '12 at 23:08
  • 2
    @Jonathan 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 *.sqlite – gerry3 Feb 16 '13 at 07:28
  • 14
    actually since Xcode 6 it seams to be somewhere inside of: ~/Library/Developer/CoreSimulator – Macilias Jun 12 '15 at 22:06
21

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

RoLYroLLs
  • 3,113
  • 4
  • 38
  • 57
  • 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. – paulvs Mar 24 '16 at 17:33
  • unfortunately https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/ is not compatible with the latest firefox. – Matthew Ferguson Nov 28 '17 at 20:03
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)
Igor Leonovich
  • 458
  • 4
  • 13
11

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

SmileBot
  • 19,393
  • 7
  • 65
  • 62
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.

Diesel
  • 519
  • 1
  • 6
  • 24
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.

Ely
  • 8,259
  • 1
  • 54
  • 67
  • 1
    Spent an hour trying other tools. This is exactly what I would expect, great tool! – Code Wiget Jun 29 '20 at 20:36
  • Just tested with an iOS simulator - UI looked promising, but app crashed within 1m consistently when selecting several tables (it is a small DB). – Nic Mar 26 '23 at 17:22
  • @Nic Please contact support@betamagic.nl so we can fix the cause of the crash. Thank you! – Ely Mar 29 '23 at 08:04
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.

2

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

cheers.bo

roberthuttinger
  • 1,172
  • 1
  • 17
  • 31
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
hashier
  • 4,670
  • 1
  • 28
  • 41
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.

nikdange_me
  • 2,949
  • 2
  • 16
  • 24