开发者

How can I create a sample SQLite DB for my iPhone app?

I'm diving in to iPhone development and I'm building an iPhone app that use开发者_Python百科s 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.


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.


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/<Username>/Library/Application Support/iPhone Simulator/User/Application/<Application GUID>/Documents/<database name.sqlite>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜