Ios – How to import a pre-existing sqlite file into Core Data

core-dataiosiphonesqlite

I need to import a .sqlite file into Core Data, I searched on the internet and found:

Core Data Tutorial: How To Preload/Import Existing Data

It is creating a Python script to populate this database by reading in the contents of our old database, and creating the appropriate rows in the new database. But my sqlite database is too large in term of number of tables and columns, this may cost me a considerable amount of time.

I also found this:

Using a Pre-Populated SQLite Database with Core Data on iPhone OS 3.0

But I don't quite understand it, it looks like it's copying old database to a new one, then how does it add Z_ suffix to all the table and column names? Also, it asks me to create entities and attributes, is there anyway this can be done automatically(from sqlite dabase file)?

Thanks!

Best Answer

This answers here might be useful (mine is one of them)

Pre-populate Core Data

 /**
 Returns the path to the application's Documents directory.
*/
      - (NSString *)applicationDocumentsDirectory {
          return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES) lastObject];
      }

sample code

Related Topic