Import CSV to CoreData storage [XCode Project]

The purpose of this project is to pre-populate SQLite storage for CoreData applications with initial (and maybe the only) data in application building stage. This is mainly useful in iPhone 3.0 apps.

The SQLite storage file will be recreated from the CSV in the phase of application package building everytime the CSV source is changed. Yet it only works for flat-table object schemes.

There are few steps to use it:

  1. Compile CSVtoCoreData project or download the binary.
  2. Copy the binary to your CoreData project, disable it for all targets (i.e. to not include it in distribution package).
  3. Add new “Run shell script” build phase with following code:

    and input and output files – first your CSV file, second the CSVtoCoreData binary and in the output one the file which the binary produces (the same as csv, but with .sqlite extension).

  4. The shell script will take the .mom Object Model File and .csv data source file, produces .sqlite file and copies it to application package.
  5. In your CoreData application you may use this file directly from application package for read-only access or copy it to Application Support or Application Documents folder for read-write access.

For more info feel free to ask.


Leave a Reply

Your email address will not be published. Required fields are marked *