Xcodegen

作者: Peter杰 | 来源:发表于2019-10-15 16:09 被阅读0次

xcodegen 简介

xcodegen是一个工具,它允许我们从名为project.yml的文件中的定义生成xcodeproj文件。

由于xcodeproj文件可以随时生成,我们甚至不必将它保存在我们的git中并且可以忽略它。

以下是xcodegen的两个最重要的功能:

可以通过这种方式为各种平台(iOS,tvOS,macOS,watchOS)定义各种 Xcode target(application,frameworks 等)。

它还允许将源文件的文件夹连接到目标,从而更容易管理哪些源代码文件包含在哪个目标中。

安装xcodegen

使用 homebrew进行安装

brew install xcodegen

生成一个App Project

首先用xcode创建一个工程,在工程的根目录创建一个 project.yml 文件内容如下,并保存文件

name: XcodegenApp # The name of the App
options: # Some general settings for the project
  createIntermediateGroups: true # If the folders are nested, also nest the groups in Xcode
  indentWidth: 2 # indent by 2 spaces
  tabWidth: 2 # a tab is 2 spaces
  bundleIdPrefix: "com.wj"
targets: # The List of our targets
  XcodegenApp:
    type: application
    platform: iOS
    deploymentTarget: "10.3"
    sources:
      #Sources
      - path: XcodegenApp

重命名.xcodeproj文件 ( 这样你可以进行对比文件的修改,或者删除)


image.png

打开终端,进入到你的工程目录

cd ~/Desktop/XcodegenApp

执行xcodegen

xcodegen

打开XcodegenApp.xcodeproj并运行, 你可以看到和原来的工程一样可正常运行


生成 TestTargets

在project.yml 文件中添加target ,并保存文件

  XcodegenApp-iOS-Tests:
    type: bundle.unit-test
    platform: iOS
    deploymentTarget: "10.3"
    sources:
      - path: XcodegenAppTests
    dependencies:
      - target: XcodegenApp

  • 关闭xcode(在xcode 工程打开的时候 进行修改文件可能有异常情况出现.)
  • 执行xcodegen,生成工程文件, 打开并运行:正常!
xcodegen

在project.yml 文件中添加 UI Tests target,并保存文件

XcodegenApp-iOS-UITests:
    type: bundle.ui-testing
    platform: iOS
    sources:
      - path: XcodegenAppUITests
    dependencies:
      - target: XcodegenApp

执行xcodegen,生成工程文件, 打开并运行:正常!

xcodegen

相关文章

网友评论

      本文标题:Xcodegen

      本文链接:https://www.haomeiwen.com/subject/hjnpsctx.html