onetwopunch
onetwopunch

Reputation: 3349

How to populate CoreData in iOS with an Android SQLite DB?

So basically I have a lot of static data in an existing Android app and I am trying to make a version of that app in iOS that uses Core Data.

I'd like to know how to use the existing Android DB file and migrate the data over programmatically.

I'd just really like to stay away from the sqlite3 stuff in iOS if possible.

Please let me know if this is possible

Upvotes: 1

Views: 368

Answers (1)

Carl Veazey
Carl Veazey

Reputation: 18363

There is no easy, one-size-fits-all approach to this. In general, these are the steps you'll want to follow:

  1. Identify the entities represented in your existing database
  2. Identify their relationships with other entities, as well as their attributes (these will probably be the foreign keys in your database and the normal columns, respectively).
  3. Create a Core Data model that corresponds to the entities, relationships, and attributes that you have identified.
  4. Using the SQLite library on iOS, write code to query your database. Use the results of your database queries to instantiate NSManagedObjects and populate the attributes and relationships that you identified earlier.

Unfortunately, there will be no way to avoid writing some code to interact with your existing database. If you wish to avoid writing C code to do so, you can check out an Objective-C library that provides an interface to the SQLite routines that's more object-oriented called FMDB.

Upvotes: 2

Related Questions