Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Xcode 4 and Xmo’d compatibility #48

MonsieurDart opened this Issue · 27 comments

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,


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...


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


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...


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...


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.


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 :-)


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?


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.


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.




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:
What project modifications do you want to perform? I can add them!


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


#  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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.