Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert parts of mySQL DB from website into CoreData/SQLite on iOS

I have a website with mySQL database, parts of which I'd like to reuse in my iPhone app by populating CoreData DB (basically iPhone app is going to be an offline version of the website).

I am thinking of writing scripts which will translate mySQL into SQLite and then somehow feed the data into CoreData.

How would you accomplish this task?

like image 596
valdyr Avatar asked Nov 24 '11 14:11

valdyr


1 Answers

Solution

Check out the following tutorial:

http://www.raywenderlich.com/980/core-data-tutorial-how-to-preloadimport-existing-data

TL;DR - uses a python script to write to the SQLite database in a Core Data compatible format.

Possible Drawbacks

  • If you've got a complex database, this could get messy fast.
  • If there's any errors in the format of the SQLite database, Core Data is not tolerant and you might get unexplained crashes.
  • Apple recommend that you never mess directly with the data store directly, which makes me a bit nervous of this approach.

Alternative

I'd dump the mySQL database to a CSV file, model the Core Data store in Xcode as unusual and write a quick and dirty importer within the application itself.

You could use cCSVParse to do the CSV heavy lifting.

like image 147
John Gallagher Avatar answered Sep 30 '22 11:09

John Gallagher