xcode 我如何使用 Mogenerator?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3563145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I use Mogenerator?
提问by Senseful
I installed Mogenerator. Now what do I do? How do I use it?
我安装了Mogenerator。现在我该怎么办?我该如何使用它?
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.
我遇到的第一个问题是我不知道它安装在哪里。在安装过程中,它只让我选择要安装的硬盘驱动器,而不是目录。最自然的位置是Applications
文件夹,但它并不存在。
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.
Xmo 的工作原理是注意您的 *.xcdatamodel 何时被保存。如果模型文件的 Xcode 项目项注释包含 xmod,则会触发 AppleScript,它会根据模型的文件名创建文件夹,并使用来自模型的派生源代码文件填充该文件夹。然后将新文件夹作为组引用添加到您的项目中,并将所有源文件添加到您的项目中。
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?
- “模型文件的 Xcode 项目项注释”指的是什么?我怎样才能让它包含“xmod”?
- 添加此评论并让 mogenerator 监视
.xcdatamodel
文件是使用 mogenerator 的唯一方法吗?有什么方法可以手动运行 mogenerator 以便它重新创建生成的文件?
采纳答案by Marcus S. Zarra
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.
我记得 mogenerator 是一个安装到您的开发人员目录中的脚本。但是,它可能安装在 ~/Library 下的 Xcode 脚本目录中。
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.
在 Xcode 中,如果您选择模型文件并点击 ?I 您将获得它的元数据。单击评论选项卡并在那里添加 xmod。mogenerator 查找该注释以了解它是否应该生成文件。
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.
您可以从命令行运行 mogenerator 并让它监视您的文件。键入mogenerator --help
在终端看到的选项。
回答by Johannes Fahrenkrug
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.
需要注意的另一个警告:您必须已经将实体的 Class 属性设置为与 NSManagedObject 不同的内容。否则 Xmo 不会做任何事情。
Note: Xmo'd currently doesn't work with Xcode 4/5, afaik.
注意:Xmo'd 目前不适用于 Xcode 4/5,afaik。
What I do is just add a "MOGenerator" target in Xcode:
我所做的只是在 Xcode 中添加一个“MOGenerator”目标:
- Go to your project and click on "Add Target..." in the "Targets" section.
- Choose "iOS -> Other -> Aggregate"
- Go to "Build Phases"
- Select from the Menu "Editor -> Add Build Phase -> Add Run Script Build Phase"
- Paste your MOGenerator command into the Run Script section, for example:
- 转到您的项目并单击“目标”部分中的“添加目标...”。
- 选择“iOS -> 其他 -> 聚合”
- 转到“构建阶段”
- 从菜单中选择“Editor -> Add Build Phase -> Add Run Script Build Phase”
- 将您的 MOGenerator 命令粘贴到运行脚本部分,例如:
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.
现在您可以通过简单地运行这个目标来更新您的 MOGenerator 生成的。
回答by Senseful
I searched my hard drive and found the following files:
我搜索了我的硬盘并找到了以下文件:
The application is installed to: /usr/bin/mogenerator
.
该应用程序安装到:/usr/bin/mogenerator
。
The /Library/Application Support/mogenerator/
directory contains some .motemplate
files.
该/Library/Application Support/mogenerator/
目录包含一些.motemplate
文件。
回答by Jake Lin
回答by Hashem Aboonajmi
using mogenerator:
使用 mogenerator:
download mogenerator
run and build the mogenerator project
locate the built file in the product group
copy the built file in to
/usr/bin
directory- 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
下载移动生成器
运行并构建 mogenerator 项目
在产品组中找到构建的文件
将构建的文件复制到
/usr/bin
目录中- 在终端中复制此代码并按回车键:
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/....
注意:这里首先我输入了 myApp.xcdatamodel 文件路径,下一个路径是生成文件的位置。如果文件路径包含空格字符,请务必在文件路径中的空格\
前添加字符。喜欢/desktop/xcode\ projects/myApp/....
enjoy!
请享用!
回答by ma11hew28
Studying line 22 of make_installer.command
, I found that /Developer/Library/Xcode/Plug-ins/Xmod.pbplugin
is also installed.
研究第22行make_installer.command
,发现/Developer/Library/Xcode/Plug-ins/Xmod.pbplugin
也安装了。
And then, searching mogenerator GitHub Issuesfor "uninstall," I found official instructions on how to uninstall mogeneratorfrom the creator himself.
然后,在mogenerator GitHub 问题中搜索“卸载”,我找到了有关如何从创建者本人那里卸载 mogenerator 的官方说明。