views:

32

answers:

2

I apologize ahead of time for what I'm sure is a complete newbie lapse. Running my iPhone app on iPhone simulator - no problem. But I loaded the app on an iPhone device for the first time and it appears as if the SQLite database I'm using (NSManagedObjectContext) isn't connected or didn't upload. The app installs but with no data. How do I get it all to upload and work on the device? I appreciate any help. lq

A: 

Looking a little deeper I found a link that answers my own question. So anyone with the same question, this solved the issue for me:

http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/

Lauren Quantrell
That is a **terrible** solution. See my answer for more details.
Marcus S. Zarra
+1  A: 

The first rule with Core Data is that you should never ever touch the store directly. It should be considered a black box and only accessed via the the Core Data APIs. Accessing the database directly is unsupported and can lead to data corruption.

What you should do instead is create a trivial desktop application (or command line is you are just importing from another source) and enter the data there. Once the data is entered then copy the sqlite file to your mobile application and include it in the bundle. That way you are accessing the file from Core Data. Since Apple can and does change the structure of that file without notice your application will be future proof.

update

If you have created a database using Core Data you can then take that sqlite file and add it to your Xcode project for your iPhone application. Xcode will then copy it into the app bundle when it compiles the project.

Marcus S. Zarra
I'm sorry I'm new at this. I have a prepopulated SQLite database. How do I include it with the bundle so that it is read by the app after the app is distributed? Isn't the solution I cite simply copying the SQLite database so that it can be read?
Lauren Quantrell