using-tuist-generated-projects

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Using Tuist Generated Projects

使用Tuist生成的项目

Quick Start

快速开始

bash
undefined
bash
undefined

Generate workspace without opening Xcode

Generate workspace without opening Xcode

tuist generate --no-open
tuist generate --no-open

Build a scheme with xcodebuild

Build a scheme with xcodebuild

xcodebuild build -workspace App.xcworkspace -scheme App
xcodebuild build -workspace App.xcworkspace -scheme App

Run tests with xcodebuild

Run tests with xcodebuild

xcodebuild test -workspace App.xcworkspace -scheme AppTests -only-testing AppTests/MyTestCase
undefined
xcodebuild test -workspace App.xcworkspace -scheme AppTests -only-testing AppTests/MyTestCase
undefined

Project definition

项目定义

Prefer buildable folders

优先使用可构建文件夹

Use
buildableFolders
instead of
sources
and
resources
globs. Buildable folders stay synchronized with the file system, so adding or removing files does not require regeneration.
swift
let target = Target(
  name: "App",
  buildableFolders: [
    "App/Sources",
    "App/Resources",
  ]
)
使用
buildableFolders
替代
sources
resources
通配符。可构建文件夹会与文件系统保持同步,因此添加或删除文件无需重新生成项目。
swift
let target = Target(
  name: "App",
  buildableFolders: [
    "App/Sources",
    "App/Resources",
  ]
)

Tag targets for focus

为目标添加标签以聚焦

Use target tags to group areas of the project, for example:
  • tag:team:*
  • tag:feature:*
  • tag:layer:*
These tags make it easier to scope generation and testing later.
Example target metadata with tags:
swift
let target = Target(
  name: "PaymentsUI",
  metadata: .metadata(tags: [
    "tag:team:commerce",
    "tag:feature:payments",
    "tag:layer:ui",
  ])
)
When working on a focused area, generate only what you need:
bash
tuist generate tag:feature:payments
tuist generate PaymentsUI PaymentsTests
使用目标标签对项目的不同区域进行分组,例如:
  • tag:team:*
  • tag:feature:*
  • tag:layer:*
这些标签便于后续限定生成和测试的范围。
带标签的目标元数据示例:
swift
let target = Target(
  name: "PaymentsUI",
  metadata: .metadata(tags: [
    "tag:team:commerce",
    "tag:feature:payments",
    "tag:layer:ui",
  ])
)
当专注于某个特定区域时,仅生成所需内容:
bash
tuist generate tag:feature:payments
tuist generate PaymentsUI PaymentsTests

Align build configurations

对齐构建配置

Keep build configurations aligned between the project and external dependencies. Use
PackageSettings(settings: .settings(configurations: []))
to mirror project configurations; mismatches emit warnings.
保持项目与外部依赖的构建配置一致。使用
PackageSettings(settings: .settings(configurations: []))
来镜像项目配置;配置不匹配会发出警告。

Workflows

工作流程

Generate intentionally

有目的地生成项目

  • Use
    tuist generate --no-open
    in automation and scripts to avoid launching Xcode.
  • Regenerate when any manifest changes (or the dependency graph changes).
  • If generation fails due to missing products, run
    tuist install
    to resolve dependencies and retry.
  • 在自动化脚本中使用
    tuist generate --no-open
    以避免启动Xcode。
  • 当任何清单文件更改(或依赖关系图更改)时重新生成项目。
  • 如果因缺少产物导致生成失败,请运行
    tuist install
    解决依赖问题后重试。

Build with xcodebuild

使用xcodebuild构建

Use
xcodebuild build
against the generated workspace and scheme.
bash
xcodebuild build \
  -workspace App.xcworkspace \
  -scheme App \
  -destination "generic/platform=iOS Simulator"
针对生成的工作区和scheme使用
xcodebuild build
bash
xcodebuild build \
  -workspace App.xcworkspace \
  -scheme App \
  -destination "generic/platform=iOS Simulator"

Test with xcodebuild

使用xcodebuild测试

Use
xcodebuild test
for running tests locally. Prefer it over
tuist test
because
tuist test
regenerates the project on each invocation, which slows down iteration.
To optimize test run time:
  • Use
    --only-testing
    to run only the specific test suite or test case you are working on, instead of the full target.
  • Pick the scheme with the fewest compilation targets that still includes the test target you need. This minimizes build time before tests run.
bash
undefined
使用
xcodebuild test
在本地运行测试。优先使用该命令而非
tuist test
,因为
tuist test
每次调用都会重新生成项目,会减慢迭代速度。
为优化测试运行时间:
  • **使用
    --only-testing
    **仅运行你正在开发的特定测试套件或测试用例,而非整个目标。
  • 选择包含最少编译目标的scheme,但要确保包含你需要的测试目标。这可以最小化测试运行前的构建时间。
bash
undefined

Run a specific test suite

Run a specific test suite

xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite
xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite

Run a single test case

Run a single test case

xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite/testMyFunction
undefined
xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite/testMyFunction
undefined

Guidelines

指导原则

  • Keep
    buildableFolders
    paths aligned to the target's real file system layout.
  • Avoid overlapping
    buildableFolders
    with
    sources
    or
    resources
    globs in the same target.
  • Open Xcode manually when needed after running
    tuist generate --no-open
    .
  • 保持
    buildableFolders
    路径与目标的实际文件系统布局一致。
  • 避免在同一目标中让
    buildableFolders
    sources
    resources
    通配符重叠。
  • 运行
    tuist generate --no-open
    后,根据需要手动打开Xcode。

Troubleshooting

故障排除

Static side effects warnings: adjust product types deliberately. Use
Target.product
for local targets and
PackageSettings(productTypes:)
for external products. Making everything dynamic with
.framework
can compile and run, but it may hurt launch time. Prefer static products (static frameworks or libraries) when possible and when they do not introduce side effects.
Objective-C dependency crashes: add
-ObjC
or
-force_load
via
OTHER_LDFLAGS
on consuming targets as needed. Reference:
https://docs.tuist.dev/en/guides/features/projects/dependencies#objectivec-dependencies
.
静态副作用警告: 谨慎调整产物类型。对本地目标使用
Target.product
,对外部产物使用
PackageSettings(productTypes:)
。将所有产物设为动态
.framework
可以编译并运行,但可能会影响启动时间。在可能且不会引入副作用的情况下,优先选择静态产物(静态框架或库)。
Objective-C依赖崩溃: 根据需要在消费目标的
OTHER_LDFLAGS
中添加
-ObjC
-force_load
。参考:
https://docs.tuist.dev/en/guides/features/projects/dependencies#objectivec-dependencies