How do I use Mogenerator?
Asked Answered
R

6

19

I installed Mogenerator. Now what do I do? How do I use it?

The first problem I have is that I have no idea where it was installed to. During the install process, it only let me select the hard drive to install it on, not the directory. The most natural location would be the Applications folder, but it isn't there.

Next, the readme (which I found online) states:

Xmo'd works by noticing when your *.xcdatamodel is saved. If the model file's Xcode project item comment contains xmod, an AppleScript is fired that creates a folder based on your model's file name and populates it with derived source code files from your model. It then adds the new folder to your project as a Group Reference and adds all the source files to your project.

There are several issues with the above statement that aren't clear:

  • What does "the model file's Xcode project item comment" refer to? How can I make it contain "xmod"?
  • Is adding this comment and having mogenerator monitor the .xcdatamodel file the only way to use mogenerator? Is there any way I can manually run mogenerator so that it recreates the generated files?
Rozella answered 25/8, 2010 at 5:46 Comment(1)
Xcode 4 Users check out [this answer][1]. [1]: #3589747Geilich
F
10

mogenerator is a script that is installed into your developer directory as I recall. However it might be installed into the Xcode scripts directory under your ~/Library.

What do you mean by manually triggering the application? You can trigger a build by "touching" the data model. Any save on the data model will trigger the build

In Xcode if you select the model file and hit ⌘I you will get its metadata. Click on the comments tab and add xmod there. mogenerator looks for that comment to know if it should generate files.

Update

You can run mogenerator from the command line as well as have it monitor your files. Type mogenerator --help in the Terminal to see the options.

Filar answered 25/8, 2010 at 5:53 Comment(3)
I updated that part to hopefully be more clear. Thanks for the answer.Rozella
⌘I is not working with the lastest Xcode versions. See the last answer to read more...Geilich
I would suggest running it from the command line. That is what I doFilar
R
17

One more caveat to be aware of: You have to already set the Class properties of your entities to something different than NSManagedObject. Otherwise Xmo'd won't do anything.

Note: Xmo'd currently doesn't work with Xcode 4/5, afaik.

What I do is just add a "MOGenerator" target in Xcode:

  1. Go to your project and click on "Add Target..." in the "Targets" section.
  2. Choose "iOS -> Other -> Aggregate"
  3. Go to "Build Phases"
  4. Select from the Menu "Editor -> Add Build Phase -> Add Run Script Build Phase"
  5. Paste your MOGenerator command into the Run Script section, for example:
PATH=${PATH}:/usr/local/bin    
cd "${PROJECT_DIR}/MyApp"
mogenerator --human-dir Classes --machine-dir MOGenerated --model MyApp.xcdatamodeld/MyApp.xcdatamodel --template-var arc=true

Now you can update your MOGenerator-generated by simply running this target.

Ramirez answered 21/10, 2010 at 10:52 Comment(5)
I think you accidently a word.Imprescriptible
Thanks! This sentence no verb.Ramirez
Thank you for this. This was the solution to my inability to get mogenerator to work. When creating a new entity in the .xcdatamodel file, you have to remember to set Class in addition to the Name; normally XCode fills it in automatically when you generate the class files I think.Sw
This saved me some time. I can't find any documentation that tells you this.Reparable
For running this automatically with every build on the main target: Go to your main target -> Build Phases -> Add Mogenerator Target under Target DependenciesMarguerite
F
10

mogenerator is a script that is installed into your developer directory as I recall. However it might be installed into the Xcode scripts directory under your ~/Library.

What do you mean by manually triggering the application? You can trigger a build by "touching" the data model. Any save on the data model will trigger the build

In Xcode if you select the model file and hit ⌘I you will get its metadata. Click on the comments tab and add xmod there. mogenerator looks for that comment to know if it should generate files.

Update

You can run mogenerator from the command line as well as have it monitor your files. Type mogenerator --help in the Terminal to see the options.

Filar answered 25/8, 2010 at 5:53 Comment(3)
I updated that part to hopefully be more clear. Thanks for the answer.Rozella
⌘I is not working with the lastest Xcode versions. See the last answer to read more...Geilich
I would suggest running it from the command line. That is what I doFilar
R
6

I searched my hard drive and found the following files:

The application is installed to: /usr/bin/mogenerator.

The /Library/Application Support/mogenerator/ directory contains some .motemplate files.

Rozella answered 25/8, 2010 at 6:31 Comment(0)
D
2

⌘I doesn't work in Xcode 4 any more. please check out the command line tool. Here is the doc

Diatribe answered 2/2, 2013 at 10:28 Comment(0)
W
0

Studying line 22 of make_installer.command, I found that /Developer/Library/Xcode/Plug-ins/Xmod.pbplugin is also installed.

And then, searching mogenerator GitHub Issues for "uninstall," I found official instructions on how to uninstall mogenerator from the creator himself.

Wrightson answered 23/4, 2011 at 16:7 Comment(0)
R
0

using mogenerator:

  1. download mogenerator

  2. run and build the mogenerator project

  3. locate the built file in the product group enter image description here

  4. copy the built file in to /usr/bin directory

  5. in the terminal copy this code and hit enter: mogenerator -m /Users/hashem/Desktop/Projects/myApp/myAppModel.xcdatamodel -O /Users/hashem/Desktop/Projects/myApp/managedObjects --template-var arc=true

NOTE: here first I have entered myApp.xcdatamodel file path, and next path is the location of generated files. if the file path contains space character be sure to add \ character before space in the file path. like /desktop/xcode\ projects/myApp/....

enjoy!

Ronnironnica answered 30/6, 2014 at 19:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.