The help for Mogenerator is very minimal. What do all the parameters do?
4 回答
Parameters that work both via the command line utility and Xcode:
--base-class
: The name af the base class which the "private class" (e.g._MyObject.h
) will inherit from. This will also add an import in the form of#import "MyManagedObject.h"
to the same.h
file. Tip: if the class you want to inherit from is located in a library, the default import statement won't work. As a workaround, you could have an extra level of inheritance for each project you create and have that class inherit from the library on (e.g. set the base class toMyProjectManagedObject
which you create manually and inherit fromMyLibManagedObject
).--template-path
: The path to where the 4.motemplate
files are located. When this is not provided, it will look at all the "app support directories" (e.g."/Library/Application Support/mogenerator/"
).--template-group
: A subdirectory name underneath thetemplate-path
directory to use.--template-var arc=true
: Required for the generated files to compile while using ARC.--output-dir
: The output directory for all generated files.--machine-dir
: The directory where the_<class>.h
and_<class>.m
will be output to. If --output-dir is also defined, this parameter takes precedence.--human-dir
: The directory where the<class>.h
and<class>.m
will be output to. If --output-dir is also defined, this parameter takes precedence.--includem
: the full path to a file that will include all the#import
for all the.h
files that are created. This file does not need to exist (i.e. it will be created for you if it doesn't). This file, will not be included in the project automatically for you. You must include it manually by dragging it into the Groups & Files list of your project.
Using relative paths in Xcode for any of the above arguments won't work since the working directory is set to one of the root directories of the system (e.g. Applications, Developer, Library, or System). (I haven't had enough time to figure out which one of these it is exactly.)
Parameters that cannot be used in Xcode:
--model
: The path to the .xcdatamodel file, cannot be set in Xcode.--list-source-files
--orphaned
--versioned
--help
Running and sending parameters to xmod via Xcode:
(Update: I haven't tried this on Xcode 4, only Xcode 3. For Xcode 4, you can add mogenerator as a build phase instead of following the following steps.)
- Go to the info page of the
.xcdatamodel
file. - Choose the Comments tab.
- Add
xmod
to the comments field, on its own line. - Every time you save the model, it will regenerate the machine files for you.
To send parameters, they must be on their own line(s):
This works:
xmod
--base-class CLASS
--template-path PATH
And even this works:
xmod
--base-class CLASS --template-path PATH
But, this won't work:
xmod --base-class CLASS --template-path PATH
Note: You must close the Info window for the settings to take effect.
从 XCode 4 开始,信息窗口不再可用,因此如果您无法按照上面的回答进行设置,请不要担心。
使用John Blanco 的指南设置脚本目标,它允许您将命令行参数直接传递给 mogenerator。请注意,您可能需要稍微调整他的示例中的路径...pwd
在脚本中折腾 a 并根据脚本的工作目录检查路径,如果它没有立即为您运行。
有关可用命令行参数的列表,请mogenerator --help
在终端中运行。AFAICT,所有这些都从脚本编写步骤开始。
如果您想在每次构建时自动重建机器文件,请参阅此答案以通过“预操作”调用 mogenerator 的另一种方法。还有一个关于将 mogenerator 脚本放入 VCS 的好技巧。
这是从 1.27 版开始的 --help 的输出
mogenerator: Usage [OPTIONS] <argument> [...]
-m, --model MODEL Path to model
-C, --configuration CONFIG Only consider entities included in the named configuration
--base-class CLASS Custom base class
--base-class-import TEXT Imports base class as #import TEXT
--base-class-force CLASS Same as --base-class except will force all entities to have the specified base class. Even if a super entity exists
--includem FILE Generate aggregate include file for .m files for both human and machine generated source files
--includeh FILE Generate aggregate include file for .h files for human generated source files only
--template-path PATH Path to templates (absolute or relative to model path)
--template-group NAME Name of template group
--template-var KEY=VALUE A key-value pair to pass to the template file. There can be many of these.
-O, --output-dir DIR Output directory
-M, --machine-dir DIR Output directory for machine files
-H, --human-dir DIR Output directory for human files
--list-source-files Only list model-related source files
--orphaned Only list files whose entities no longer exist
--version Display version and exit
-h, --help Display this help and exit
Implements generation gap codegen pattern for Core Data.
Inspired by eogenerator.
另外,也许会有帮助。用于确定哪些参数可用于
--template-var KEY=VALUE
打开 *.motemplate 文件,找到类似“TemplateVar”的字符串。之后,您将看到参数名称并能够理解它的作用。
此参数具有内置模板
--template-var arc=true
--template-var frc=true
--template-var modules=true