views:

42

answers:

1

I'm working on an iPhone app that uses NSURLConnection to down load files and then convert those files into sqlite3 tables. I would like to use core data to store these tables and to create all the applicable objects. So, do I have to build the models of the data in XCode with the graphical tool representing all the table names and columns? I've been searching and found examples of apps that use core data and copy in a pre populated sqlite file for the default data. The data that I'm working with will have some variations in the table names and column name and types. Any direction would be appreciated.

+1  A: 

You need to load the database via a Core Data model within a Core Data application. You can't use a sqlite database that was not created with Core Data (without a huge amount of unsupported pain).

Core Data databases created with applications on Mac OS X are compatible with Core Data applications on iOS. I know of a number of developers that have written little command line tools that run as a part of building their iOS application that effectively "compile" a database that is then copied into the application's app wrapper.

bbum
Is there a way to build the Core Data model dynamically?
fmcauley
Yes -- but that would be a highly unusual solution (and, no, you can't dynamically build one to map to an arbitrary sqlite database). See the docs; all the API is there to do so.
bbum
Upon further reading in the Core Data doc: "Important: Although Core Data supports SQLite as one of its persistent store types, Core Data cannot manage any arbitrary SQLite database. In order to use a SQLite database, Core Data must create and manage the database itself. For more about store types, see “Persistent Store Features.”
fmcauley