Build Status

MotoSwift. 将托管对象转换为 Swift 代码。

生成 Swift NSManagedObject 子类。

优势

为什么比 Xcode 生成更好?

  1. Xcode 生成属性时忽略了可选标志
  2. 允许使用模板自定义生成的代码
  3. 允许为转换属性指定类型

为什么比 Mogenerator 更好?

  1. 允许为机器代码生成扩展

此外,它允许为整个模型生成一个文件,例如,您需要实体名称列表

安装

  1. 通过从 最新的 GitHub 发布页面 下载 MotoSwift.pkg 并运行来安装 MotoSwift。

  2. 从源代码安装。

克隆或下载项目。

运行 make install

如果您需要将所有组件放在一个文件夹中,请运行 make bundle。 现在您可以复制整个 motoswift 文件夹,并从任何位置运行 motoswift/bin/motoswift

用法

示例

  1. Xcode 样式

motoswift human --template ./Templates/xcode/class.stencil --output ./SampleOutput/Xcode --file-mask "{{class}}+CoreDataClass.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

motoswift machine --template ./Templates/xcode/properties.stencil --output ./SampleOutput/Xcode --file-mask "{{class}}+CoreDataProperties.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Xcode

  1. Mogenerator 样式

motoswift human --template ./Templates/mogenerator/human.stencil --output ./SampleOutput/Mogenerator/Human --file-mask "{{class}}.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Mogenerator/Human

motoswift machine --template ./Templates/mogenerator/machine.stencil --output ./SampleOutput/Mogenerator/Machine --file-mask "_{{class}}.swift" ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Mogenerator/Machine

  1. 所有实体和字段名称

motoswift model --template ./Templates/model.stencil --output ./SampleOutput/Model/Model.swift ./Tests/MotoSwiftFrameworkTests/Resources/TypesModel.xcdatamodeld

SampleOutput/Model/Model.swift

测试

make test

发布

make .package

其他文档

MotoSwift 使用 Stencil 作为模板语言