views:

59

answers:

2

Hi all, this is my first question here.

Well, I am developing an iPhone application that will use coredata, but the theres not going to be an option to insert data into the database of the app.

I want to know how to pre-populate it's database.

I thought of creating a plist with all the info and make a function to put it all into the coredata database if the database is not set yet...

but I want to know if it is the right way to do so.

Thanks all.

+1  A: 

You can pre-create the database file (sqlite file) using your device and put that in the bundle when you distribute it. When you run the app for the first time you can move that from your applications bundle you can move it to the documents directory where core data will read it.

You can also have a function that runs at the start of your applications first run where it reads from your plist and creates the appropriate objects.

DHamrick
I thought of doing that, but is it the best practice ?
Joao H Neves
A: 

The easiest way is to create a desktop application with the same model (the exact same model even, just link it in). Then have Interface Builder create you a default UI for it and enter the data. Far easier than doing it on a device.

Once you have the data then include the SQLite file in your bundle and since your app is read only as you claimed; point the NSPersistentStoreCoordinator at the file in your app bundle and Bob's your uncle.

Creating an app on the desktop takes about 5 minutes and will save you far more time on the data entry side.

Marcus S. Zarra
Worked just fine !. Thanks
Joao H Neves