Integrate mogenerator within Xcode 4
Asked Answered
I

2

5

In my application I'm using Core Data stuff to enable persistent data saving. Since I've seen that mogenerator provides a good approach to create and maintain NSManagedObject subclasses (also with additional functionalities), I'm looking for some tips for integrating monogenerator within Xcode 4?

P.S. The question has been submitted based on share your knowledge, Q&A-style.

Ileana answered 28/11, 2012 at 16:8 Comment(0)
A
14

For Xcode 4.5+, the easiest way is to setup a "Pre-action" in your scheme:

  1. Edit the scheme you want to build
  2. Open the "Build" item and select "Pre-actions"
  3. Click on the "+" and add a "New Run Script Action"
  4. In the "Provide build settings from" popup, use the target
  5. Paste this in the text area:

    # Update the mogenerator files  
    cd ${SOURCE_ROOT}/${PROJECT_NAME}  
    /usr/bin/mogenerator --template-var arc=true -m ${PROJECT_NAME}.xcdatamodeld -M CoreData/Machine -H CoreData/Human`
    
  6. Hit "OK" and build

A directory named "CoreData" will be created in your source file area along with the subdirectories "Human" and "Machine". You should now add the "CoreData" folder to your project.

Antilebanon answered 3/2, 2013 at 5:8 Comment(1)
My correct mark goes to you since it's receiving more upvotes. Thanks for sharing.Ileana
I
2

Using mogenerator within Xcode 4 is quite simple.

First of all, download it at mogenerator.

Once done, switch to your Xcode project and, within the Project navigator, select your project (e.g. ProjectName). Select ProjectName under TARGETS section. Hold Add Build Phase. A menu appears. Select Add Run Script. A new run script will appear. Within the text area (under shell field), add some text like the following.

cd ProjectName mogenerator --template-var arc=true --model DataModel.xcdatamodeld/DataModel.xcdatamodel

Et voilà. When you build the project you should be able to see generated classes.

For other info and options you should refer to mogenerator wiki.

Hope it helps.

P.S. Feel free to comment or modify the answer if something is wrong.

Ileana answered 28/11, 2012 at 16:8 Comment(1)
Pro Tip: Put any "Run Script" build phase scripts in an external file in the project file directory then put "./BuildScripts/run_mogenerator.sh " in Xcode. This way it is easier to track changes to the script without getting lost in the other project commits.Thoroughbred

© 2022 - 2024 — McMap. All rights reserved.