using-tuist-generated-projects
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsing Tuist Generated Projects
使用Tuist生成的项目
Quick Start
快速开始
bash
undefinedbash
undefinedGenerate 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
undefinedxcodebuild test -workspace App.xcworkspace -scheme AppTests -only-testing AppTests/MyTestCase
undefinedProject definition
项目定义
Prefer buildable folders
优先使用可构建文件夹
Use instead of and globs. Buildable folders stay synchronized with the file system, so adding or removing files does not require regeneration.
buildableFolderssourcesresourcesswift
let target = Target(
name: "App",
buildableFolders: [
"App/Sources",
"App/Resources",
]
)使用替代和通配符。可构建文件夹会与文件系统保持同步,因此添加或删除文件无需重新生成项目。
buildableFolderssourcesresourcesswift
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 PaymentsTestsAlign build configurations
对齐构建配置
Keep build configurations aligned between the project and external dependencies. Use to mirror project configurations; mismatches emit warnings.
PackageSettings(settings: .settings(configurations: []))保持项目与外部依赖的构建配置一致。使用来镜像项目配置;配置不匹配会发出警告。
PackageSettings(settings: .settings(configurations: []))Workflows
工作流程
Generate intentionally
有目的地生成项目
- Use in automation and scripts to avoid launching Xcode.
tuist generate --no-open - Regenerate when any manifest changes (or the dependency graph changes).
- If generation fails due to missing products, run to resolve dependencies and retry.
tuist install
- 在自动化脚本中使用以避免启动Xcode。
tuist generate --no-open - 当任何清单文件更改(或依赖关系图更改)时重新生成项目。
- 如果因缺少产物导致生成失败,请运行解决依赖问题后重试。
tuist install
Build with xcodebuild
使用xcodebuild构建
Use against the generated workspace and scheme.
xcodebuild buildbash
xcodebuild build \
-workspace App.xcworkspace \
-scheme App \
-destination "generic/platform=iOS Simulator"针对生成的工作区和scheme使用。
xcodebuild buildbash
xcodebuild build \
-workspace App.xcworkspace \
-scheme App \
-destination "generic/platform=iOS Simulator"Test with xcodebuild
使用xcodebuild测试
Use for running tests locally. Prefer it over because regenerates the project on each invocation, which slows down iteration.
xcodebuild testtuist testtuist testTo optimize test run time:
- Use to run only the specific test suite or test case you are working on, instead of the full target.
--only-testing - 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 testtuist testtuist test为优化测试运行时间:
- **使用**仅运行你正在开发的特定测试套件或测试用例,而非整个目标。
--only-testing - 选择包含最少编译目标的scheme,但要确保包含你需要的测试目标。这可以最小化测试运行前的构建时间。
bash
undefinedRun a specific test suite
Run a specific test suite
xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite
xcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite
-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
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite/testMyFunction
undefinedxcodebuild test
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite/testMyFunction
-workspace App.xcworkspace
-scheme AppTests
-only-testing AppTests/MyTestSuite/testMyFunction
undefinedGuidelines
指导原则
- Keep paths aligned to the target's real file system layout.
buildableFolders - Avoid overlapping with
buildableFoldersorsourcesglobs in the same target.resources - Open Xcode manually when needed after running .
tuist generate --no-open
- 保持路径与目标的实际文件系统布局一致。
buildableFolders - 避免在同一目标中让与
buildableFolders或sources通配符重叠。resources - 运行后,根据需要手动打开Xcode。
tuist generate --no-open
Troubleshooting
故障排除
Static side effects warnings: adjust product types deliberately. Use for local targets and for external products. Making everything dynamic with 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.
Target.productPackageSettings(productTypes:).frameworkObjective-C dependency crashes: add or via on consuming targets as needed. Reference: .
-ObjC-force_loadOTHER_LDFLAGShttps://docs.tuist.dev/en/guides/features/projects/dependencies#objectivec-dependencies静态副作用警告: 谨慎调整产物类型。对本地目标使用,对外部产物使用。将所有产物设为动态可以编译并运行,但可能会影响启动时间。在可能且不会引入副作用的情况下,优先选择静态产物(静态框架或库)。
Target.productPackageSettings(productTypes:).frameworkObjective-C依赖崩溃: 根据需要在消费目标的中添加或。参考:。
OTHER_LDFLAGS-ObjC-force_loadhttps://docs.tuist.dev/en/guides/features/projects/dependencies#objectivec-dependencies