views:

200

answers:

2

I'm diving in to iPhone development and I'm building an iPhone app that uses the Core Data framework and my first task will be to get the model setup with a view that will display it. Thus far, I have the model defined and my Managed Object Files created, but I don't have a database with any sample data.

  1. What's a quick way to create a DB that conforms to my schema?
  2. Are there any tools that can generate a sample DB using my schemas? Or do I have to create this sample data by hand?
  3. Once the DB is created, are there any good tools I can use to directly manipulate the data in DB for testing purposes?

Thanks in advance for your help! I'm going to continue researching this question right now.

+2  A: 

This is very close to the question "Provide Base Data for Core Data Application?" Additionally, my answer to this question describes how you can quickly build a Mac application that lets you create or edit a Core Data database that is compatible with your iPhone application's data model.

Beyond that, you can use the application Core Data Editor to do what its name describes.

Brad Larson
A: 

I assume you've already created a working app that uses sqlite as persistent storage for your data model.

Have a look into the AppDelegate.m file to search for the sqlite database name and location, then run your app in the iPhone Simulator.

Use Spotlight to search for the SQLite database created by the app in the simulator, usually this is /Users//Library/Application Support/iPhone Simulator/User/Application//Documents/

Now you only have to copy that file to a working folder, open it using sqlite3 (www.sqlite.org), then type .schema to retrieve the database schema.

Now populate it, either by hand or using a python/ruby/whatever script! Unfortunately, i'm not aware of any tool that will populate a db by simply feeding them the schema. For directly manipulating the data, sqlite3 provides you with a command line utility that's really handy for that purpose.

When you're finished, add the file with sample data to your App project.

Daniele Milan
Editing a Core Data model's raw SQLite is a bad idea, because the internal data format is complex and undocumented. It's much easier and safer to work with it through a Mac application that understands the structure of the Core Data model.
Brad Larson
Agreed, using Code Data Editor is indeed a better option.
Daniele Milan