Generator and Xcode 4

I just installed mogenerator + xmo'd on my development machine and would like to start playing with it. The only instructions that I could really find on the Internet were previous SO posts , and they do not work with Xcode 4 (or at least I don't pull up the metadata and I don't know how).

So, so that everything is in order and working, all that needs to happen is to add xmod to the xmod comments (wherever they are), and the classes will be generated / updated with conservation from now on?

+8
xcode core-data mogenerator
source share
5 answers

While trying to find this answer, I found a guide to integrate MOGenerator and Xcode 4 on esenciadev.com. This solution is not button integration, but it works. The link contains detailed instructions, but usually you:

  • Copy shell scripts to your project
  • Add build rules for your purpose to run two shell scripts

When creating a project, the script starts MOGenerator for all .xcdatamodel files in the project directory. After the build, if the script creates new class files, you must manually add them to your project. Subsequent builds will remember the existing MO-Generated files.

Cautions:

  • The example building rule assumes that you place the scripts in the / scripts / file folder in the project directory. When I ignored this detail (creating a project folder, but not a file folder), I got a build error. Make sure the build rule points to the location of the script file.

  • script uses the argument --base-class . If your model classes are not subclasses of the custom class (and not NSManagedObject), you should remove this argument from the script. For example,

 mogenerator --model "${INPUT_FILE_PATH}/$curVer" --output-dir "${INPUT_FILE_DIR}/"   --base-class $ baseClass 
+7
source share

Now that Xcode 4 is released, check out the Issues page for mogenerator

+5
source share

After making changes to the model file, I simply start mogenerator manually from the terminal. Using Xcode 4 and ARC, this does the trick:

 cd <directory of model file> mogenerator --model <your model>.xcdatamodeld/<current version>.xcdatamodel --template-var arc=YES 

Maybe at some point I will use build scripts, but the terminal approach is too simple to mess up.

+4
source share

I found Script in Build Phases more reliable than Build Rules.

In the "Build Phases" section, for your purpose, select the button at the bottom of the "Add Script Run" button. Drag the Script run to the beginning so that it runs before compiling the sources.

Remember that the actual data model files (.xcdatamodel) are contained in the package (.xcdatamodeld) and that you only need to collect the latest data model for your project.

Add the following to Script (replacing the text in parentheses)

 MODELS_DIR="${PROJECT_DIR}/<path to your models without trailing slash>" DATA_MODEL_PACKAGE="$MODELS_DIR/<your model name>.xcdatamodeld" CURRENT_VERSION=`/usr/libexec/PlistBuddy "$DATA_MODEL_PACKAGE/.xccurrentversion" -c 'print _XCCurrentVersionName'` # Mogenerator Location if [ -x /usr/local/bin/mogenerator ]; then echo "mogenerator exists in /usr/local/bin path"; MOGENERATOR_DIR="/usr/local/bin"; elif [ -x /usr/bin/mogenerator ]; then echo "mogenerator exists in /usr/bin path"; MOGENERATOR_DIR="/usr/bin"; else echo "mogenerator not found"; exit 1; fi $MOGENERATOR_DIR/mogenerator --model "$DATA_MODEL_PACKAGE/$CURRENT_VERSION" --output-dir "$MODELS_DIR/" 

Add mogenerator options if necessary. --base-class <your base class> and --template-var arc=true are common.

+1
source share

Random tip. If you get illegal instructions: 4 when you start mogenerator. Install it from the command line:

 $ brew update && brew upgrade mogenerator 
0
source share

All Articles