Mogenerator 和 Xcode 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5118718/
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
Mogenerator and Xcode 4
提问by Bill Shiff
I just installed mogenerator+xmo'd on my development machine and would like to start playing with it. The only instructions I could really find online were from a previous SO post, and those don't work with XCode 4 (or at least ?I doesn't pull up metadata any more and I don't know how).
我刚刚在我的开发机器上安装了 mogenerator+xmo'd,并想开始使用它。我真正能在网上找到的唯一说明来自之前的 SO 帖子,这些说明不适用于 XCode 4(或至少?我不再提取元数据,我不知道如何)。
So to get things up and running, is all that needs to happen to add xmod
in the .xcdatamodeld's comments (wherever they are) and the classes will be generated/updated on save from then on?
因此,为了让一切正常运行,是否需要添加xmod
.xcdatamodeld 的注释(无论它们在哪里),并且从那时起将在保存时生成/更新类?
回答by jluckyiv
While trying to find this answer myself, I found MOGenerator and Xcode 4 integration guideon esenciadev.com. This solution is not a push-button integration, but it works. The link has detailed instructions, but generally you:
在尝试自己找到这个答案时,我在esenciadev.com 上找到了MOGenerator 和 Xcode 4 集成指南。此解决方案不是一键式集成,但它有效。该链接有详细说明,但通常您:
- Copy the shell scripts into your project
- Add build rules to your target to run the two shell scripts
- 将 shell 脚本复制到您的项目中
- 向目标添加构建规则以运行两个 shell 脚本
When you build your project, the script runs MOGenerator on all .xcdatamodel files in your project directory. After the build, if the script generates newclass files, you must manually add them to your project. Subsequent builds will remember existing MO-Generated files.
构建项目时,脚本会在项目目录中的所有 .xcdatamodel 文件上运行 MOGenerator。构建后,如果脚本生成新的类文件,您必须手动将它们添加到您的项目中。后续构建将记住现有的 MO 生成文件。
Caveats:
注意事项:
The example's build rule assumes you put the scripts into a /scripts/ file folder within your project directory. When I ignored this detail (creating a projectfolder but not a filefolder) I got a build error. Make sure the build rule points to the script's file location.
The script uses the
--base-class
argument. Unless your model classes are subclasses of a custom class (not NSManagedObject), you must delete this argument from the script. E.g.,
该示例的构建规则假定您将脚本放入项目目录中的 /scripts/ 文件夹中。当我忽略这个细节(创建一个项目文件夹而不是一个文件夹)时,我得到了一个构建错误。确保构建规则指向脚本的文件位置。
脚本使用
--base-class
参数。除非您的模型类是自定义类(不是 NSManagedObject)的子类,否则您必须从脚本中删除此参数。例如,
mogenerator --model "${INPUT_FILE_PATH}/$curVer" --output-dir "${INPUT_FILE_DIR}/" --base-class $baseClass
回答by Brent Priddy
回答by Neal Ehardt
After I make changes to my model file, I just run mogenerator manually from the terminal. Using Xcode 4 and ARC, this does the trick:
更改模型文件后,我只需从终端手动运行 mogenerator。使用 Xcode 4 和 ARC,这可以解决问题:
cd <directory of model file>
mogenerator --model <your model>.xcdatamodeld/<current version>.xcdatamodel --template-var arc=YES
Maybe I'll use build scripts at some point, but the terminal approach is too simple to screw up.
也许我会在某个时候使用构建脚本,但终端方法太简单了,不会搞砸。
回答by Ryan
I've found a Script in the "Build Phases" to be more reliable than the "Build Rules".
我发现“构建阶段”中的脚本比“构建规则”更可靠。
Under "Build Phases" for your Target, choose the button at the bottom to "Add Run Script". Drag the run script to the top so that it executes before compiling sources.
在目标的“构建阶段”下,选择底部的按钮以“添加运行脚本”。将运行脚本拖到顶部,以便在编译源代码之前执行。
Remember that the actual data model files (.xcdatamodel) are contained within a package (.xcdatamodeld), and that you only need to compile the latest data model for your project.
请记住,实际的数据模型文件 (.xcdatamodel) 包含在包 (.xcdatamodeld) 中,您只需为您的项目编译最新的数据模型。
Add the following to the script (replacing text in angle-brackets as appropriate)
将以下内容添加到脚本中(根据需要替换尖括号中的文本)
MODELS_DIR="${PROJECT_DIR}/<path to your models without trailing slash>"
DATA_MODEL_PACKAGE="$MODELS_DIR/<your model name>.xcdatamodeld"
CURRENT_VERSION=`/usr/libexec/PlistBuddy "$DATA_MODEL_PACKAGE/.xccurrentversion" -c 'print _XCCurrentVersionName'`
# Mogenerator Location
if [ -x /usr/local/bin/mogenerator ]; then
echo "mogenerator exists in /usr/local/bin path";
MOGENERATOR_DIR="/usr/local/bin";
elif [ -x /usr/bin/mogenerator ]; then
echo "mogenerator exists in /usr/bin path";
MOGENERATOR_DIR="/usr/bin";
else
echo "mogenerator not found"; exit 1;
fi
$MOGENERATOR_DIR/mogenerator --model "$DATA_MODEL_PACKAGE/$CURRENT_VERSION" --output-dir "$MODELS_DIR/"
Add options to mogenerator
as appropriate. --base-class <your base class>
and --template-var arc=true
are common.
根据需要添加选项mogenerator
。--base-class <your base class>
并且 --template-var arc=true
很常见。
回答by Matt Hudson
Random tip. If you get Illegal Instruction: 4 when you run mogenerator. Install it from the command line:
随机提示。如果您在运行 mogenerator 时收到 Illegal Instruction: 4。从命令行安装它:
$ brew update && brew upgrade mogenerator