views:

483

answers:

2

I have an existing application using Core Data on the iPhone. Occasionally there would be updates to the application's data delivered as updates to the App Store. In my perfect world, building an application to edit the data in the updates with an OS X application and copying the sqlite database to my iPhone app bundle would be a relatively pain-free way to do this.

Is it possible to move sqlite database (assuming they use the same data model) between OS X and iPhone OS?

What are the things I should watch out for that isn't portable between (like 32-bit vs. 64-bit data)?

Are there better alternatives that I'm overlooking?

A: 

Yes, you can do this. The problem cones when you need to change database schema; so you might want to consider doing a dump of the data into a different format and then reloading if you need to push out new versions.

AlBlue
There is no problem with changing the schema either. Core Data supports versioning both on the iPhone and on the desktop and the API is the same. In fact both will do minor schema changes automatically without the need of even a mapping model.
Marcus S. Zarra
+5  A: 

The SQLite format is identical between Mac and iPhone applications with the same data model. It's pretty trivial to generate a Mac application to edit your database (I do this for my iPhone application). In fact, you can take your data model and quickly drag and drop an interface for it (from the Core Data Programming Guide FAQ):

In Mac OS X v10.5 and later, in Interface Builder you can drag a Core Data Entity item from the Library onto a window or box. Interface Builder then presents a panel that allows you to select the entity you want from the currently-open Xcode projects.

Note that you can also create and configure an NSController instance in Interface Builder. As in the case of creating a user interface, you Option-click an entity in the Data Modeling tool in Xcode (or select the Core Data Entity item from the Library), but you drag it to a the Interface Builder file window. For editing one object, an NSObjectController instance is created; for editing many objects, an NSArrayController instance is created.

I'd also check out Core Data Editor, which loads in your compiled managed object model and lets you edit your database from that.

Brad Larson