Mogenerator and Xcode 4
Asked Answered
L

5

8

I just installed mogenerator+xmo'd on my development machine and would like to start playing with it. The only instructions I could really find online were from a previous SO post, and those don't work with XCode 4 (or at least ⌘I doesn't pull up metadata any more and I don't know how).

So to get things up and running, is all that needs to happen to add xmod in the .xcdatamodeld's comments (wherever they are) and the classes will be generated/updated on save from then on?

Lippe answered 25/2, 2011 at 15:0 Comment(3)
Xcode 4's still subject to an NDA, so you shouldn't/won't be able to get an answer here.Halfmast
Try the Apple Developer forums. You can discuss NDA material there.Thermobarometer
You can use the command line to solve this issue, if you're still interested in the answer, i'll post a response that will solve the issus for youCacia
S
7

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

  1. Copy the shell scripts into your project
  2. Add build rules to your target to run the two shell scripts

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

Caveats:

  1. The example's build rule assumes you put the scripts into a /scripts/ file folder within your 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 script's file location.

  2. The script uses the --base-class argument. Unless your model classes are subclasses of a custom class (not NSManagedObject), you must delete this argument from the script. E.g.,

mogenerator --model "${INPUT_FILE_PATH}/$curVer" --output-dir "${INPUT_FILE_DIR}/" --base-class $baseClass
Shuttering answered 26/7, 2011 at 4:12 Comment(2)
The tutorial provided seems to include some unnecessary steps. Does anyone know why mogen.sh and mogend.sh are both needed? Wouldn't running a custom script that simply calls mogenerator on the current version of hhe datamodel be adequate?Propagandize
I think so. I was unfamiliar with mogenerator when I posted. After reading your comment, I tried using the mogend.sh script and it seems to work fine.Shuttering
A
5

Now that Xcode 4 is released Take a look at the Issues page for mogenerator

Anarthrous answered 11/3, 2011 at 5:11 Comment(0)
F
4

After I make changes to my model file, I just run 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 I'll use build scripts at some point, but the terminal approach is too simple to screw up.

Fernferna answered 4/5, 2012 at 19:7 Comment(0)
T
1

I've found a Script in the "Build Phases" to be more reliable than the "Build Rules".

Under "Build Phases" for your Target, choose the button at the bottom to "Add Run Script". Drag the run script to the top so that it executes before compiling sources.

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

Add the following to the script (replacing text in angle-brackets as appropriate)

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 options to mogenerator as appropriate. --base-class <your base class> and --template-var arc=true are common.

Tatianatatianas answered 5/4, 2012 at 5:29 Comment(0)
C
0

Random tip. If you get Illegal Instruction: 4 when you run mogenerator. Install it from the command line:

$ brew update && brew upgrade mogenerator
Conduct answered 5/6, 2013 at 23:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.