views:

20

answers:

1

What's a good pattern, if any, to share a piece of Core Data model across iPhone apps the same way I would share code, images and other resources?

I am thinking of developing my model in one app, and then just including it in the other app as a resource. But can't wrap my head around how to do that. Is it sufficient to just include the generated model code files, which I could include as code? But this does not feel right, I think I need the actual data model file too, which is some opaque resource. But say that both of the apps have also other Core Data model objects that I don't want to share across them? (if I do want to share everything, I guess I could share the xcdatamodeld files, but I specifically want to share only an isolated part of the graph.)

To make a concrete example, app 1 has model objects A and B that are related, and C and D that are related. A-B, though, are not related to C-D. App 2 has C-D and E-F. I would like to share C-D (the two model objects and their relation) between the apps, the goal being that the schema updates stay in sync between apps. (Sharing only model, not data.)

+2  A: 

Since stores are created by merging the models on hand in any particular app, you can mix models however you wish. However, once you create a store with a particular set of model files, you must have those model files always available in the future.

TechZen
Can you elaborate a bit about how this would actually work in Xcode given my example?
Jaanus
Use `Project>Add To Project...` In the app 1 project, just add the individual model files A,B,C,D. As long as the models don't define the same entities, they merge without a problem. In the app 2 project, just add individual model files C,D,E,F. In the `Add To Project` dialog it gives you the option to copy the file to project. Don't copy but use the same files in both apps so that you only change one file.
TechZen