Mogenerator 和 Xcode 4

发布于 2024-10-19 08:48:41 字数 304 浏览 0 评论 0原文

我刚刚在我的开发机器上安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

逆光下的微笑 2024-10-26 08:48:41

在尝试自己找到这个答案时,我发现了 MOGenerator 和 Xcode 4 集成指南 esenciadev.com。该解决方案不是按钮式集成,但它确实有效。该链接有详细说明,但通常您可以:

  1. 将 shell 脚本复制到项目中
  2. 将构建规则添加到目标以运行两个 shell 脚本

当您构建项目时,脚本会在项目目录中的所有 .xcdatamodel 文件上运行 MOGenerator。构建后,如果脚本生成类文件,您必须手动将它们添加到您的项目中。后续构建将记住现有的 MO 生成的文件。

注意事项:

  1. 该示例的构建规则假设您将脚本放入项目目录中的 /scripts/ 文件夹中。当我忽略此详细信息(创建 project 文件夹而不是 file 文件夹)时,我收到了构建错误。确保构建规则指向脚本的文件位置。

  2. 该脚本使用 --base-class 参数。除非您的模型类是自定义类(不是 NSManagedObject)的子类,否则您必须从脚本中删除此参数。例如,

mogenerator --model "${INPUT_FILE_PATH}/$curVer" --output-dir "${INPUT_FILE_DIR}/" --base-class $baseClass

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:

  1. Copy the shell scripts into your project
  2. Add build rules to your target to run the two shell scripts

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:

  1. 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.

  2. 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.,

mogenerator --model "${INPUT_FILE_PATH}/$curVer" --output-dir "${INPUT_FILE_DIR}/" --base-class $baseClass
小梨窩很甜 2024-10-26 08:48:41

现在 Xcode 4 已发布,请查看 mogenerator 的问题页面

Now that Xcode 4 is released Take a look at the Issues page for mogenerator

后来的我们 2024-10-26 08:48:41

对模型文件进行更改后,我只需从终端手动运行 mogenerator。使用 Xcode 4 和 ARC,这可以解决问题:

cd <directory of model file>
mogenerator --model <your model>.xcdatamodeld/<current version>.xcdatamodel --template-var arc=YES

也许我会在某个时候使用构建脚本,但终端方法太简单了,不会搞砸。

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:

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.

不念旧人 2024-10-26 08:48:41

我发现“构建阶段”中的脚本比“构建规则”更可靠。

在目标的“构建阶段”下,选择底部的按钮“添加运行脚本”。将运行脚本拖到顶部,以便它在编译源之前执行。

请记住,实际的数据模型文件 (.xcdatamodel) 包含在包 (.xcdatamodeld) 中,并且您只需为项目编译最新的数据模型。

将以下内容添加到脚本中(根据需要替换尖括号中的文本)

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/"

根据需要向 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)

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.

久光 2024-10-26 08:48:41

随机提示。如果您在运行 mogenerator 时收到 Illegal instructions: 4。从命令行安装它:

$ brew update && brew upgrade mogenerator

Random tip. If you get Illegal Instruction: 4 when you run mogenerator. Install it from the command line:

$ brew update && brew upgrade mogenerator
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文