问题
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.
回答1:
For Xcode 4.5+, the easiest way is to setup a "Pre-action" in your scheme:
- Edit the scheme you want to build
- Open the "Build" item and select "Pre-actions"
- Click on the "+" and add a "New Run Script Action"
- In the "Provide build settings from" popup, use the target
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`
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.
回答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.
来源:https://stackoverflow.com/questions/13609384/integrate-mogenerator-within-xcode-4