Mogenerator 和 Xcode 4
我刚刚在我的开发机器上安装了 mogenerator+xmo'd,并想开始使用它。我真正能在网上找到的唯一说明来自之前的一篇文章,而这些说明并没有无法与 XCode 4 一起使用(或者至少 ⌘我不再提取元数据,而且我不知道如何操作)。
因此,为了让事情启动并运行,是否需要在 .xcdatamodeld 的注释(无论它们在哪里)中添加 xmod
,并且从那时起,类将在保存时生成/更新?
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).
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在尝试自己找到这个答案时,我发现了 MOGenerator 和 Xcode 4 集成指南 esenciadev.com。该解决方案不是按钮式集成,但它确实有效。该链接有详细说明,但通常您可以:
当您构建项目时,脚本会在项目目录中的所有 .xcdatamodel 文件上运行 MOGenerator。构建后,如果脚本生成新类文件,您必须手动将它们添加到您的项目中。后续构建将记住现有的 MO 生成的文件。
注意事项:
该示例的构建规则假设您将脚本放入项目目录中的 /scripts/ 文件夹中。当我忽略此详细信息(创建 project 文件夹而不是 file 文件夹)时,我收到了构建错误。确保构建规则指向脚本的文件位置。
该脚本使用
--base-class
参数。除非您的模型类是自定义类(不是 NSManagedObject)的子类,否则您必须从脚本中删除此参数。例如,While trying to find this answer myself, I found MOGenerator and Xcode 4 integration guide on esenciadev.com. This solution is not a push-button integration, but it works. The link has detailed instructions, but generally you:
When you build your project, the script runs MOGenerator on all .xcdatamodel files in your project directory. After the build, if the script generates new class files, you must manually add them to your project. Subsequent builds will remember existing MO-Generated files.
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 project folder but not a file folder) 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.,现在 Xcode 4 已发布,请查看 mogenerator 的问题页面
Now that Xcode 4 is released Take a look at the Issues page for mogenerator
对模型文件进行更改后,我只需从终端手动运行 mogenerator。使用 Xcode 4 和 ARC,这可以解决问题:
也许我会在某个时候使用构建脚本,但终端方法太简单了,不会搞砸。
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:
Maybe I'll use build scripts at some point, but the terminal approach is too simple to screw up.
我发现“构建阶段”中的脚本比“构建规则”更可靠。
在目标的“构建阶段”下,选择底部的按钮“添加运行脚本”。将运行脚本拖到顶部,以便它在编译源之前执行。
请记住,实际的数据模型文件 (.xcdatamodel) 包含在包 (.xcdatamodeld) 中,并且您只需为项目编译最新的数据模型。
将以下内容添加到脚本中(根据需要替换尖括号中的文本)
根据需要向
mogenerator
添加选项。--base-class <您的基类>
和--template-var arc=true
很常见。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.
Add the following to the script (replacing text in angle-brackets as appropriate)
Add options to
mogenerator
as appropriate.--base-class <your base class>
and--template-var arc=true
are common.随机提示。如果您在运行 mogenerator 时收到 Illegal instructions: 4。从命令行安装它:
Random tip. If you get Illegal Instruction: 4 when you run mogenerator. Install it from the command line: