building-apple-platform-products
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuilding Apple Platform Products
构建Apple平台产品
Build, test, and archive Swift packages and Xcode projects for Apple platforms.
为Apple平台构建、测试并归档Swift包与Xcode项目。
When to Use This Skill
何时使用该技能
Use this skill when you need to:
- Build an iOS, macOS, tvOS, watchOS, or visionOS app
- Build a Swift package
- Run unit tests or UI tests
- Create an archive for distribution
- Discover project structure (schemes, targets, configurations)
当你需要以下操作时使用该技能:
- 构建iOS、macOS、tvOS、watchOS或visionOS应用
- 构建Swift包
- 运行单元测试或UI测试
- 创建用于分发的归档文件
- 探索项目结构(schemes、targets、配置)
Tool Selection
工具选择
| Project Type | Primary Tool | When to Use |
|---|---|---|
Standalone | | Libraries, CLI tools, cross-platform Swift (no .xcodeproj) |
| | CocoaPods or multi-project setups |
| | Standard Xcode projects (including those with SPM dependencies) |
Important: The / commands only work for standalone Swift packages. If a Swift package is embedded as a submodule within an Xcode project, you must use with the appropriate scheme—the Swift CLI cannot orchestrate builds in that context.
swift buildswift testxcodebuild| 项目类型 | 主要工具 | 使用场景 |
|---|---|---|
独立 | | 库、CLI工具、跨平台Swift项目(无.xcodeproj) |
| | CocoaPods或多项目配置 |
| | 标准Xcode项目(包含SPM依赖的项目) |
重要提示: / 命令仅适用于独立Swift包。如果Swift包作为子模块嵌入到Xcode项目中,必须使用并指定对应的scheme——Swift CLI无法在此场景下协调构建。
swift buildswift testxcodebuildProject Discovery
项目探索
Before building, discover the project structure:
bash
undefined在构建前,先探索项目结构:
bash
undefinedFind what project files exist
查找存在的项目文件
ls Package.swift *.xcworkspace *.xcodeproj 2>/dev/null
ls Package.swift *.xcworkspace *.xcodeproj 2>/dev/null
List schemes and targets (auto-detects project)
列出schemes与targets(自动检测项目)
xcodebuild -list
xcodebuild -list
Describe package (standalone SPM only)
描述包信息(仅适用于独立SPM项目)
swift package describe
**Note**: When an Xcode project references a local Swift package, each package **target** gets its own scheme (named after the target, not the package). Use these schemes to build individual targets without building the entire app.
For mixed projects, shared schemes, or detailed output parsing, see [project-discovery.md](references/project-discovery.md).swift package describe
**注意**:当Xcode项目引用本地Swift包时,每个包**target**会拥有自己的scheme(以target命名,而非包名)。可使用这些scheme来构建单个target,无需构建整个应用。
对于混合项目、共享scheme或需要解析详细输出的场景,请查看[project-discovery.md](references/project-discovery.md)。Swift Package Manager Commands
Swift Package Manager命令
Important: These commands only work for standalone Swift packages, not Swift Package Manager submodules in Xcode projects.
| Goal | Command |
|---|---|
| Build (debug) | |
| Build (release) | |
| Run executable | |
| Run tests | |
| Run specific test | |
| Show binary path | |
| Clean | |
| Initialize | |
For cross-compilation, Package.swift syntax, or dependency management, see swift-package-manager.md.
重要提示:这些命令仅适用于独立Swift包,不适用于Xcode项目中的Swift Package Manager子模块。
| 目标 | 命令 |
|---|---|
| 构建(debug模式) | |
| 构建(release模式) | |
| 运行可执行文件 | |
| 运行测试 | |
| 运行指定测试 | |
| 显示二进制文件路径 | |
| 清理 | |
| 初始化 | |
如需了解交叉编译、Package.swift语法或依赖管理,请查看swift-package-manager.md。
xcodebuild Commands
xcodebuild命令
Command structure:
xcodebuild [action] -scheme <name> [-workspace|-project] [options] [BUILD_SETTING=value]| Goal | Command |
|---|---|
| List schemes | |
| Build | |
| Test | |
| Build for testing | |
| Test without build | |
| Archive | |
| Clean | |
Required: is always required. Add or when multiple exist.
For tests: is required for iOS/tvOS/watchOS/visionOS targets.
-scheme-workspace-project-destinationFor build settings, SDK selection, or CI configuration, see xcodebuild-basics.md.
命令结构:
xcodebuild [action] -scheme <name> [-workspace|-project] [options] [BUILD_SETTING=value]| 目标 | 命令 |
|---|---|
| 列出schemes | |
| 构建 | |
| 测试 | |
| 为测试构建 | |
| 不构建直接测试 | |
| 归档 | |
| 清理 | |
必填项:始终为必填项。当存在多个项目文件时,需添加或。
测试相关:针对iOS/tvOS/watchOS/visionOS target,为必填项。
-scheme-workspace-project-destination如需了解构建设置、SDK选择或CI配置,请查看xcodebuild-basics.md。
Common Destinations
常用目标配置
| Platform | Destination Specifier |
|---|---|
| macOS | |
| iOS Simulator | |
| iOS Device | |
| tvOS Simulator | |
| watchOS Simulator | |
| visionOS Simulator | |
| Generic (build only) | |
Note: Simulator names change with each Xcode release. Always verify available simulators:
bash
xcrun simctl list devices availableFor all platforms, multiple destinations, or troubleshooting destination errors, see destinations.md.
| 平台 | 目标指定参数 |
|---|---|
| macOS | |
| iOS模拟器 | |
| iOS设备 | |
| tvOS模拟器 | |
| watchOS模拟器 | |
| visionOS模拟器 | |
| 通用(仅构建) | |
注意:模拟器名称会随Xcode版本更新而变化。请始终通过以下命令验证可用模拟器:
bash
xcrun simctl list devices available如需了解全平台支持、多目标配置或目标参数排障,请查看destinations.md。
Reference Files
参考文件
| Topic | File | When to Read |
|---|---|---|
| Project Discovery | project-discovery.md | Mixed projects, shared schemes |
| Swift Package Manager | swift-package-manager.md | Cross-compilation, Package.swift syntax |
| xcodebuild Basics | xcodebuild-basics.md | Build settings, SDK selection |
| Destinations | destinations.md | All platforms, multiple destinations |
| Testing | testing.md | Test filtering, parallel execution, coverage |
| Archiving | archiving.md | Archive creation |
| Troubleshooting | troubleshooting.md | Build/test failures, error recovery |
| 主题 | 文件 | 阅读场景 |
|---|---|---|
| 项目探索 | project-discovery.md | 混合项目、共享scheme |
| Swift Package Manager | swift-package-manager.md | 交叉编译、Package.swift语法 |
| xcodebuild基础 | xcodebuild-basics.md | 构建设置、SDK选择 |
| 目标配置 | destinations.md | 全平台支持、多目标配置 |
| 测试 | testing.md | 测试过滤、并行执行、覆盖率 |
| 归档 | archiving.md | 归档文件创建 |
| 故障排除 | troubleshooting.md | 构建/测试失败、错误恢复 |
Common Pitfalls
常见误区
- swift build with Xcode submodules: Only works for standalone packages. Use with the package's scheme instead.
xcodebuild - Missing destination for iOS: Use for builds, or specify a simulator for tests.
-destination 'generic/platform=iOS' - Unnecessary workspace flag: Only use for CocoaPods or multi-project setups. Standard projects with SPM dependencies just use
-workspace..xcodeproj - Case-sensitive scheme names: Run to see exact scheme names.
xcodebuild -list - Outdated simulator names: Names change with Xcode versions. Run .
xcrun simctl list devices available - Code signing errors: Add for builds that don't require signing.
CODE_SIGNING_ALLOWED=NO
- 使用swift build处理Xcode子模块:仅适用于独立包。请改用带包scheme的命令。
xcodebuild - iOS项目缺少目标配置:构建时使用,测试时指定模拟器。
-destination 'generic/platform=iOS' - 不必要的workspace参数:仅在CocoaPods或多项目配置场景下使用。包含SPM依赖的标准项目只需使用
-workspace。.xcodeproj - scheme名称大小写敏感:运行查看准确的scheme名称。
xcodebuild -list - 模拟器名称过时:名称随Xcode版本变化。运行查看最新列表。
xcrun simctl list devices available - 代码签名错误:对于无需签名的构建,添加参数。
CODE_SIGNING_ALLOWED=NO