3

Can I inspect a Core Data model from Xcode?

I want to see if the data are correctly stored into the database.

Cœur
  • 37,241
  • 25
  • 195
  • 267
aneuryzm
  • 63,052
  • 100
  • 273
  • 488

3 Answers3

2

You can use this tool http://christian-kienle.de/CoreDataEditor

You can inspect all datas from your persistent store

Pixman
  • 599
  • 6
  • 17
1

There's no direct "show me some data stored at some path I specified somewhere in my code or at runtime that happens to use this model" feature.

If you want to view a file easily in Xcode, you'll need to add the file to your project (don't let it copy into project - just reference it in place) so you can select it in the navigator.

Caveat: This only works for text-based store types (like XML or some custom text-based store type you cooked up). If you use binary or SQLite store types, all you'll see is binary. There's no SQLite database browsing/editing functions in Xcode.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • ok, so how do you inspect the database ? Do you fetch the results with objective - c ? – aneuryzm May 10 '11 at 07:16
  • Sorry, your second sentence is not clear to me. My file (I guess you refer to .xcdatamodeld is already inside my project, so I can already select it in the navigator, but I see only the model and not the data inside (even if they have been previously permanently stored. – aneuryzm May 10 '11 at 07:18
  • That's because the managed object model source file is not the same thing as a data file *created* using that model. You really need to read the Core Data documentation front to back as you're missing some very important concepts. – Joshua Nozzi May 10 '11 at 16:14
  • To answer your question, yes, you could do it yourself with Objective-C but there're already good SQLite tools out there, so your best bet might be to use the SQLite store type and use one of the SQLite browser tools mentioned. – Joshua Nozzi May 10 '11 at 16:15
  • @JoshuaNozzi This is a pretty old question. Is your answer still correct? – codecowboy Jul 20 '15 at 06:38
  • Yes. There's still no data browser built in. Be kinda hard to when you consider transformables, data types, etc. – Joshua Nozzi Jul 20 '15 at 11:39
0

I have not come across a way to check the Core Data Modal directly from Xcode... right now I use "SQlite Database Browser" to check my database... its a good way to check your data in the database.. you can also execute queries on it...

P.S. If you do come across a way to check the Core Data Modal directly from Xcode, please do post it as an answer here...

learner2010
  • 4,157
  • 5
  • 43
  • 68
  • @learner2010 ok, I'm a newbie so I ask: can you open xcdatamodeld files with SQlite Database Browser ? Or you have to necessarily specify in objective - c you want a SQlite permanent database in your app ? – aneuryzm May 10 '11 at 07:20
  • ok.. so the xcdatamodelid files will just show you how you have set up ur entities and their attributes.. as far as I know it does not show you the data stored in them.. so that is why as per your question " I would like to see if the data is stored properly into the database" , that is why I had mentioned SQLite database browser which allows you to check the data stored in the database... – learner2010 May 10 '11 at 14:02
  • @learner2010 Can I inspect the data stored in my iOS application with SQlite Database Browser or you are just mentioning it as example of tool to inspect databases ? – aneuryzm May 10 '11 at 14:11
  • yeah... you can inspect data stored in your database via SQLite Database browser.. all you have to do is install the software, then go to your .sqlite file ( for example yourproject.sqlite) and open using sqlite database browser.. – learner2010 May 10 '11 at 14:16
  • @learner2010 Should I (1) convert my Core Data Model into SQLite database just before to inspect it, or (2) is there an option to store my data as SQLite instead of Core Data Model ? – aneuryzm May 10 '11 at 14:21
  • ummm... I am not exactly sure how to answer your question because I am new too.. but if you could post this question as a separate question, i think you might get a better response than mine.. let me know if you do find the answer to this question.. sorry for not being able to help... – learner2010 May 10 '11 at 14:28
  • also.. it would be great if you could do me a small favour.. not that in your app, you load data to your database, do you have a .sqlite file?? if so, could you download that database browser and see if you can see your data?? – learner2010 May 10 '11 at 14:45
  • @learner2010 I don't have a sqlite file in my app, this is actually what I'm asking in all my comments. – aneuryzm May 10 '11 at 15:20
  • oh oh... ok.. dint think about that... then for using the database browser I was talking about, you would have to convert your core data model into sqlite database... – learner2010 May 10 '11 at 15:21