Question

Is it possible to generate an xcdatamodel file and then import that file into Xcode? I need to create a data model for an iOS app from an existing schema specified by an industry standard. The result will be around two hundred Core Data entities with a gazillion attributes, relationships, etc, etc. It's just plain big. Being an old Unix guy, I would prefer to write some scripts to generate the xcdatamodel file rather than spend two months entering it manually via the Xcode GUI which would, of course, be error prone. The XML in the xcdatamodel file seems very straight forward. I've looked everywhere and can find no reference of anybody trying this even though it doesn't seem like that big of deal to me. Any comments or suggestions?

Was it helpful?

Solution

As you note, the model file is just XML, and for Xcode 4.0+ the format is easy to read and reverse engineer. There's nothing magic about creating one in Xcode, and no reason not to do it outside of Xcode if you can get the syntax right.

A couple of things to keep in mind:

  • You probably want to generate a xcdatamodeld that can contain multiple versions, even if you only have one version so far. It'll be better for long term maintenance.
  • You can verify that you have a valid model file at the command line using xcrun momc $FILE, which is the command-line version of having Xcode compile it.
  • If you update your generated model file, Xcode may not notice the change, so you might need to clean and build after model updates.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top