This project aims to make it easy to see differences in different
versions (e.g. git diff) of .xcdatamodel files used to describe Core
Data managed object models. An example git diff output follows:
diff --git a/Recipes.xcdatamodel/elements b/Recipes.xcdatamodel/elements
index 35a20f3..939bc61 100644
--- a/Recipes.xcdatamodel/elements
+++ b/Recipes.xcdatamodel/elements
@@ -2,8 +2,8 @@ Entity: Image (NSManagedObject)
Att: image Transformable O dafQGIhBFATAxE1hyQd5z5cpRg0OLP4+M+W3+xhA6jU=
Rel: recipe Recipe image Nullify I fVH2lmmkHE4j/FvzfJ2et3KsNxcA8p5BJp2d/xd4hH0=
-Entity: Ingredient (Ingredient) 5tCLlA1r9p1UWdOTr3XJ+ZzBr6bxraWAs3Vt9zCAZek=
- Att: amount String O b9/jjR2iJtm4oldVJwj25X+/hpEL6/1CM5hLhgV48Iw=
+Entity: Ingredient (Ingredient) 7nbTTDaWG1lAddHYHum4xP4IA/N90NYv9GLkGK+sueQ=
+ Att: amount Integer16 O RmH9Sk61kxsb8+GUEqlEkIuV4tDjxxhMNsHUu/tBW6I=
Att: displayOrder Integer16 kMPJ+qU+fnBipO5Ajep+KT3rKB9zeOPrav0q4rMSt7k=
Att: name String jLmWXAAxrGiROYTzEQlBrZZTlb6f2bF9575UvHrUaJA=
Rel: recipe Recipe ingredients Nullify O I GvmjTsOh76OGkr0Lmnxdh8u6FO4E+iuEYa0mRZPuKJQ=
The project contains a script, print_xcdatamodel, which prints a
textual representation of a .xcdatamodel file. This script as the
textconv program for a diff driver in git (see Installation below).
print_xcdatamodel works by compiling the xcdatamodel file to a mom
file using the momc compiler. The compiled mom file is then read by
another program, MOMPrinter, which also ships with this
project. MOMPrinter takes a .mom file as input and prints a detailed
description of the data model on standard output.
-
Copy
print_xcdatamodelto your$PATH -
Build
MOMPrinterand copy the binary to your path
-
Open the
MOMPrinterproject in Xcode and build with release configuration -
Right click on Products > MOMPrinter in the project navigator, then click 'Show in Finder' to locate the binary
-
Copy the binary to your
$PATHAlternatively, you can build the project on the command line using xcodebuild.
-
Ensure that
momcis available in your $PATH. For Xcode 4.3.2, themomcbinary can be found at/Applications/Xcode.app/Contents/Developer/usr/bin/momc -
Set up
git diffto useprint_xcdatamodelfor xcdatamodel files
-
Add the following line to your projects
.gitattributesfile (if you want this to apply globally, you can use~/.gitattributes)elements diff=xcdatamodelThis tells to use
xcdatamodelas the diff driver for .xcdatamodel/elements files (which contain your model's entire definition). What exactly is thisxcdatamodeldriver? That is defined in the next section. -
We can set up the
xcdatamodeldriver usinggit config. Use these commands to set up the driver (use the--globaloption if you want to set up the driver for all your projects)git config diff.xcdatamodel.xcfuncname ^Entity git config diff.xcdatamodel.textconv print_xcdatamodel
Now, whenever you use any git command which shows a diff output
(e.g. git diff, git log -p, git show, etc.) and there's a change
in an xcdatamodel file, you should be able to understand easily what
changes have been made to the data model.