In a previous project, I built an iPhone app for 2.2.x that used SQLite. It had existing data (in XML form) that needed to be pre-loaded into the build. So I wrote a small tool which used libxml2 to parse the XML, and then write out an SQLite database, which then was included directly in the build as a resource. This worked out great.
I will be starting a new project for a different client in a few weeks that has mostly the same parameters. I will have some existing data I will need to parse and dump into a file that the app will display. However, this time around I'd like to use Core Data and build the app for 3.x devices. However, I don't have explicit and direct access to the underlying database schema that Core Data uses. (Which is kind of the point of Core Data)
How can I pre-load existing data into a Core Data-based iPhone app? Can I automate the process (similar to what I did above with SQLite)?
Best Answer
I'm a little late to this party, but i'm doing something similar for GroceryList. I have data stored in plist files that i need in my CoreData sqlite store. I wrote a command line foundation tool that runs on my Mac which parses the plist files and then using my Core Data object model creates a sqlite store. I run this command line tool as part of my build (for some build configurations) so that i can regenerate the data at will. To create this kind of tool in xcode, select File -> New Project -> Mac OS X -> Command Line Tool and select "Core Data" from the "type" menu. Here's some sample code: