Xcode 4 and Xmo’d compatibility #48

MonsieurDart opened this Issue Feb 23, 2011 · 28 comments


None yet

Now that Apple is trying to force us to use Xcode 4, I'm in front of a problem: it seems Xmo'd doesn't work with this major Xcode release. Is there a solution for that out there? If not, are you planning on adding the support for Xcode 4 anytime soon? Can I help on that?


Yup, Xmo'd doesn't work with Xcode 4 since v4 doesn't load .pbplugins any more. This looks interesting as a way to migrate Xmo'd to an .xcplugin.

Once loaded, the next obstacle is to discover whether swizzling -[XDPersistenceDocumentController saveModelToFile:] is still the best way to get notifications of model file changes.

Finally, how much you wanna bet Apple changed/broke Xcode's AppleScript interface, so chances are there's work to be done there as well.

If Xcode seriously breaks the AppleScript interface again, I'm of the opinion that a pure Obj-C implementation would be preferable. We'd have to use a lot more internal APIs, but Xcode's internal APIs are more stable and make more sense than their AppleScript interface,

vguerci commented Feb 24, 2011

I tried to port AppleScript for Xcode 4. It can be done, but that's awful... I guess Applescript coding is not completed yet. Imho, that GM of Xcode 4 is anyway more a RC / Beta than a gold. But I still prefer it and use it.
For now, I use mogenerator from command line... (and if really needed use Xmod from v3)

That Xcode plugin template is quite empty and pretty useless... :( but i agree native plugin is THE way. AppleScript, you know, bleh. Xcode internal APIs are not documented, isn't?


Thanks for your quick help guys! I'll do as you do: use the command line, or maybe add it to the target if I need it to be automatized...

vguerci commented Mar 6, 2011

Side note, GTM provides a xcplugin source code, with class-dump-ed Xcode headers...
A good base to start a mogenerator plugin imho :)

prime31 commented Mar 11, 2011

Has anyone come up with a solution to the AppleScript breaking? The only outstanding issue I see is that a file reference can no longer be added to a build phase (add modelSrcFileRef to targetItr). I have tried everything under the sun to get this to work but have not successfully added a single file to any phase...

vguerci commented Mar 11, 2011

Could you gist your changes? I would help with pleasure.
Last attempt I did on Beta was horrible, Applescript API wasn't done, from what I've just seen, it looks now more complete...

prime31 commented Mar 11, 2011

vguerci, I don't have any changes to gist. Everything I tried failed. I tried manually creating the build files which didnt work, creating the file references while in the context of the build phase and anything else I could think of all failed.

vguerci commented Mar 11, 2011

I've just gave a look into Xcode 4 Applescript... Thought it was better than beta, it is not. Still a terrible mess I think... But maybe I'm missing something.
Where you could simply get xmod data model by using:
set modelList to every file reference of _project whose file kind is "wrapper.xcdatamodel" and comments contains "xmod", you now have (like in Xcode beta) to recursive browse groups / items hierarchy to get it. (please tell me I'm wrong)

There is a (new?) appealing Xcode application > data model property, which just brings... nothing.
And those To be removed suite and Xcode 3 xxxx types are just... scary.
I don't think I'll look further in this for a while... maybe at next Xcode version or maybe directly in a native coded obj-c .xcplugin...


vguerci and prime31:

I really appreciate you guys digging into this. The first time I'll have to look at this is late next week. Godspeed on your efforts :-)

noirs commented May 16, 2011

Any news regarding Xmo'd Xcode 4 compatibility?


I too am in the list of those who carefully await for your hard work to be completed! Any news?

vguerci commented May 25, 2011

I'm afraid doing an Xcode 4 plugin with that no so documented API is not that easy.
And that could easily break with Xcode versions upgrades...

That's really a weak point of Xcode, Visual Studio in comparison has tons of wonderful add-ons thanks to its (probably documented) API.

I'm still using command-line, with manually adding files to Xcode project... still a good productivity boost. :)


I'm using the command line tool too, and that's not bad! I think it will suffice, thank you!


have we found any solution to this? If not, is there a good place for documentation on the command line tool version?
With Xcode 3 pretty much gone, this will soon be our only option.


The best guide I've found to the command line tool is at this page:

I do not think anyone has ported this project to Xcode 4 yet. The command
line tool works just great, by the way!

2011/6/14 mknippen <

have we found any solution to this? If not, is there a good place for
documentation on the command line tool version?
With Xcode 3 pretty much gone, this will soon be our only option.

Reply to this email directly or view it on GitHub:
#48 (comment)


for those that have mogenerator working via command line in xcode 4, can you put together a very simplistic dummies guide? would be very much appreciated.


burnsoft: mogenerator --help gives pretty-good list of mogenerator's arguments. Personally, before Xmo'd, I used to keep a mogenerate.command double-clickable shell script that I would manually run after modifying a model. Here's an example mogenerate.command file.


I've been creating a separate Xcode build target that contains just a shell script build phase to run the command line tool. It's pretty quick to switch to that target after making any model changes.

But adding and removing new and deleted .h and .m files from the project is still a manual process. Is there any way to automate those short of an Xcode plugin?


danieldickison: check out the --includem and master's --includeh options


ok, so I'm in the folder where my model is:
mogenerator --model myModel.xcdatamodeld --base-class People
but I get this:
Assertion failed: (model), function -[MOGeneratorApp setModel:], file /Users/wolf/code/github/mogenerator/mogenerator.m, line 432.
Abort trap

any ideas?


and am I correct in assuming that mogenerator will create both the Model and _Model files if I just use
mogenerator --model myModel.xcdatamodeld

thanks for all the help so far.


You have to point to the correct model, not the parent directory. I.e.
something like this:

mogenerator --model myModel.xcdatamodeld/myModel.xcdatamodel

2011/6/15 Burnsoft <

and am I correct in assuming that mogenerator will create both the Model
and _Model files if I just use
mogenerator --model myModel.xcdatamodeld

thanks for all the help so far.

Reply to this email directly or view it on GitHub:
#48 (comment)



vguerci commented Jun 15, 2011

Here is a small script I use that auto pick current version of a versioned model, that could help :

modelversion=$(/usr/libexec/PlistBuddy -c 'print _XCCurrentVersionName' $modeld/.xccurrentversion)
echo "Mo'Generating code for $model..."
mogenerator -m "$model"\
 --base-class MyBaseManagedObject\
 --template-path templates\
 --machine-dir Generated\
 --includeh MyModelEntities.h

I wrote an Xcode plugin that might help with the situation: https://github.com/larsxschneider/Xcode-Scripting-Interface
What project modifications do you want to perform? I can add them!

adib commented Nov 28, 2011

Here is a script that I use to update the generated files. Put this in a subfolder of your project (like BuildScripts for example)


#  update_mo.sh
#  Updates Core Data generated classes - requires mogenerator
#  Created by Sasmito Adibowo on 28-11-11.


function update_model()

    fileDir=`dirname "${1}"`
    curVer=`/usr/libexec/PlistBuddy "${1}/.xccurrentversion" -c 'print _XCCurrentVersionName'`

    echo mogenerator  --model "${1}/$curVer" --output-dir "${fileDir}/" --base-class $baseClass  --template-var arc=true
    mogenerator  --model "${1}/$curVer" --output-dir "${fileDir}/" --base-class $baseClass  --template-var arc=true

find .. -iname \*.xcdatamodeld -print0 | while read -d $'\0' i; do update_model "$i"; done

larsxschneider: thanks for the offer, but if it comes down to bypassing AppleScript and using Xcode internals to update group files, I'd prefer if Xmo'd did that directly. But I'll probably be able to poach from your code, thanks!

justin commented Dec 26, 2015

Xmod is RIP.

@justin justin closed this Dec 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment