SwiftGen 使用教程
SwiftGen项目地址:https://gitcode.com/gh_mirrors/swi/SwiftGen
1. 项目的目录结构及介绍
SwiftGen 是一个用于自动生成资源代码的工具,其 GitHub 仓库的目录结构如下:
SwiftGen/
├── Documentation/
├── Examples/
├── Package.swift
├── README.md
├── Scripts/
├── Sources/
├── Tests/
├── Templates/
└── swiftgen.yml
- Documentation/: 包含项目的文档文件,如使用说明、配置指南等。
- Examples/: 包含示例项目,展示如何使用 SwiftGen。
- Package.swift: Swift 包管理文件,用于 Swift 包管理器。
- README.md: 项目的介绍文件,包含基本的使用说明和安装指南。
- Scripts/: 包含一些辅助脚本。
- Sources/: 项目的源代码文件。
- Tests/: 项目的测试文件。
- Templates/: 包含用于生成代码的模板文件。
- swiftgen.yml: 项目的配置文件,用于定义各种解析器和参数。
2. 项目的启动文件介绍
SwiftGen 的启动文件是 swiftgen
命令行工具。你可以通过以下方式安装和启动:
brew update
brew install swiftgen
安装完成后,你可以通过以下命令启动 SwiftGen:
swiftgen
3. 项目的配置文件介绍
SwiftGen 的配置文件是 swiftgen.yml
,它定义了各种解析器和参数。你可以通过以下命令生成一个示例配置文件:
swiftgen config init
生成的 swiftgen.yml
文件内容如下:
input_dir: Resources
output_dir: Generated
strings:
paths: en.lproj/Localizable.strings
templateName: structured-swift5
output: Strings.swift
xcassets:
paths: Assets.xcassets
templateName: swift5
output: Assets.swift
fonts:
paths: Fonts
templateName: swift5
output: Fonts.swift
- input_dir: 输入文件的目录。
- output_dir: 输出文件的目录。
- strings: 字符串文件的解析配置。
- xcassets: 资源文件的解析配置。
- fonts: 字体文件的解析配置。
通过编辑 swiftgen.yml
文件,你可以自定义 SwiftGen 的行为,以适应你的项目需求。