views:

73

answers:

3

Hi,

I have recently developed an app using core data as the storage db. The app allowed the user to read and write to the db. I am now developing a new app which the user doesnt need to write anything to the db, instead the app just needs to read the data. The data has relationships etc so cannot just use a plist or something similar. My question is should I use core data for such a requirement and if so how would i go about entering the data and then releasing the app. Would I have to code the data entry which would populate the db then remove all this code (as I dont want the database to repopulate every time the user opens the app)?? Is there a way to create a core data model using sql commands as with sqlite ie insert into..... etc?

Any ideas/thoughts would be very helpful.

Many thanks

Jules

+3  A: 

Yes, if you use an SQL Lite database, you can distribute a pre-populated version of it with your app. Here's another similar SO question as well

Eric Petroelje
Thanks for your quick response.....So is this the only/best way to achieve the pre loaded db? Would apps such as trivial pursuit use such methods for example (obviously this would be guess work, but in your opinion)??Many thanksJules
Jules
+1 Everything that ships with the app has to be in the app bundle. You can easily include a pre-populated database but it will always be read only. Your only other option is to include all the data in an XML and then generate the DB in the app's directories upon first launch. User's usually don't like the latter because it bogs their shiny new app.
TechZen
Thank you for all your help, it seems a pre populated sqlite db is the more efficient way to go.
Jules
+1  A: 

In my short experience with the iPhone, you have two options.

  1. Write a data import function and run it on the first application launch.
  2. Use solution 1, but build the initial sqllite file in the simulator, and then on first application launch, copy it into the app's documents directory.

From past experience, option 2 is much quicker for user experience, and the preferred solution.

Travis
A: 

You can write a utility project that imports the app's data model and use throwaway code n that project to populate the Core Data DB. Once the DB is populated, simply copy the actual file to the app project's resources folder and then when you set up your persistent store, use NSBundle to return the path to the DB file within the built app.

And you're done.

TechZen