home / skills / kylehughes / apple-platform-build-tools-claude-code-plugin / building-apple-platform-products

building-apple-platform-products skill

/skills/building-apple-platform-products

This skill helps you build, test, and archive Apple platform projects by auto-discovering schemes and destinations for swift build, xcodebuild, or swift test.

npx playbooks add skill kylehughes/apple-platform-build-tools-claude-code-plugin --skill building-apple-platform-products

Review the files below or copy the command above to add this skill to your agents.

Files (8)
SKILL.md
5.9 KB
---
name: building-apple-platform-products
description: Builds, tests, and archives Swift packages and Xcode projects for Apple platforms. Use when running xcodebuild, swift build, or swift test commands, discovering schemes and targets, or selecting simulator destinations for iOS, macOS, tvOS, watchOS, or visionOS.
---

# Building Apple Platform Products

Build, test, and archive Swift packages and Xcode projects for Apple platforms.

## 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)

## Tool Selection

| Project Type | Primary Tool | When to Use |
|--------------|--------------|-------------|
| Standalone `Package.swift` | `swift build` | Libraries, CLI tools, cross-platform Swift (no .xcodeproj) |
| `.xcworkspace` | `xcodebuild -workspace` | CocoaPods or multi-project setups |
| `.xcodeproj` | `xcodebuild` | Standard Xcode projects (including those with SPM dependencies) |

**Important**: The `swift build` / `swift test` commands only work for **standalone Swift packages**. If a Swift package is embedded as a submodule within an Xcode project, you must use `xcodebuild` with the appropriate scheme—the Swift CLI cannot orchestrate builds in that context.

## Project Discovery

Before building, discover the project structure:

```bash
# Find what project files exist
ls Package.swift *.xcworkspace *.xcodeproj 2>/dev/null

# List schemes and targets (auto-detects project)
xcodebuild -list

# Describe package (standalone SPM only)
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 Manager Commands

**Important**: These commands only work for standalone Swift packages, not Swift Package Manager submodules in Xcode projects.

| Goal | Command |
|------|---------|
| Build (debug) | `swift build` |
| Build (release) | `swift build -c release` |
| Run executable | `swift run [<target>]` |
| Run tests | `swift test` |
| Run specific test | `swift test --filter <TestClass.testMethod>` |
| Show binary path | `swift build --show-bin-path` |
| Clean | `swift package clean` |
| Initialize | `swift package init [--type library\|executable]` |

For cross-compilation, Package.swift syntax, or dependency management, see [swift-package-manager.md](references/swift-package-manager.md).

## xcodebuild Commands

**Command structure**: `xcodebuild [action] -scheme <name> [-workspace|-project] [options] [BUILD_SETTING=value]`

| Goal | Command |
|------|---------|
| List schemes | `xcodebuild -list` |
| Build | `xcodebuild build -scheme <name>` |
| Test | `xcodebuild test -scheme <name> -destination '<spec>'` |
| Build for testing | `xcodebuild build-for-testing -scheme <name> -destination '<spec>'` |
| Test without build | `xcodebuild test-without-building -scheme <name> -destination '<spec>'` |
| Archive | `xcodebuild archive -scheme <name> -archivePath <path>.xcarchive` |
| Clean | `xcodebuild clean -scheme <name>` |

**Required**: `-scheme` is always required. Add `-workspace` or `-project` when multiple exist.
**For tests**: `-destination` is required for iOS/tvOS/watchOS/visionOS targets.

For build settings, SDK selection, or CI configuration, see [xcodebuild-basics.md](references/xcodebuild-basics.md).

## Common Destinations

| Platform | Destination Specifier |
|----------|----------------------|
| macOS | `'platform=macOS'` |
| iOS Simulator | `'platform=iOS Simulator,name=iPhone 17'` |
| iOS Device | `'platform=iOS,id=<UDID>'` |
| tvOS Simulator | `'platform=tvOS Simulator,name=Apple TV'` |
| watchOS Simulator | `'platform=watchOS Simulator,name=Apple Watch Series 11 (46mm)'` |
| visionOS Simulator | `'platform=visionOS Simulator,name=Apple Vision Pro'` |
| Generic (build only) | `'generic/platform=iOS'` |

**Note**: Simulator names change with each Xcode release. Always verify available simulators:
```bash
xcrun simctl list devices available
```

For all platforms, multiple destinations, or troubleshooting destination errors, see [destinations.md](references/destinations.md).

## Reference Files

| Topic | File | When to Read |
|-------|------|--------------|
| Project Discovery | [project-discovery.md](references/project-discovery.md) | Mixed projects, shared schemes |
| Swift Package Manager | [swift-package-manager.md](references/swift-package-manager.md) | Cross-compilation, Package.swift syntax |
| xcodebuild Basics | [xcodebuild-basics.md](references/xcodebuild-basics.md) | Build settings, SDK selection |
| Destinations | [destinations.md](references/destinations.md) | All platforms, multiple destinations |
| Testing | [testing.md](references/testing.md) | Test filtering, parallel execution, coverage |
| Archiving | [archiving.md](references/archiving.md) | Archive creation |
| Troubleshooting | [troubleshooting.md](references/troubleshooting.md) | Build/test failures, error recovery |

## Common Pitfalls

1. **swift build with Xcode submodules**: Only works for standalone packages. Use `xcodebuild` with the package's scheme instead.
2. **Missing destination for iOS**: Use `-destination 'generic/platform=iOS'` for builds, or specify a simulator for tests.
3. **Unnecessary workspace flag**: Only use `-workspace` for CocoaPods or multi-project setups. Standard projects with SPM dependencies just use `.xcodeproj`.
4. **Case-sensitive scheme names**: Run `xcodebuild -list` to see exact scheme names.
5. **Outdated simulator names**: Names change with Xcode versions. Run `xcrun simctl list devices available`.
6. **Code signing errors**: Add `CODE_SIGNING_ALLOWED=NO` for builds that don't require signing.

Overview

This skill builds, tests, and archives Swift packages and Xcode projects for Apple platforms. It automates selection of the correct toolchain (swift build / swift test or xcodebuild), discovers schemes and targets, and helps choose simulator or device destinations for iOS, macOS, tvOS, watchOS, and visionOS builds.

How this skill works

The skill inspects the repository for Package.swift, .xcworkspace, and .xcodeproj files to decide whether to use Swift Package Manager or xcodebuild. It lists schemes and targets, runs build/test/archive commands with appropriate flags, and selects destinations (simulator or device) when required. It also exposes common build settings useful for CI and troubleshooting code-signing or destination issues.

When to use it

  • Build or archive an app or framework for iOS, macOS, tvOS, watchOS, or visionOS.
  • Run unit tests or UI tests and target specific simulators or devices.
  • Build standalone Swift packages or run SwiftPM tests.
  • Discover project structure: schemes, targets, and configurations before automated builds.
  • Integrate builds into CI pipelines that need deterministic xcodebuild or swift build invocations.

Best practices

  • Detect repo type first: use swift build/test only for standalone Package.swift projects.
  • Always run xcodebuild -list to get exact, case-sensitive scheme names before invoking builds.
  • Specify -workspace when CocoaPods or multiple projects exist; otherwise pass -project or let xcodebuild auto-detect.
  • For tests on Apple platforms, always provide -destination; use generic/platform for device-less builds.
  • Avoid code-signing problems in CI by setting CODE_SIGNING_ALLOWED=NO for unsigned builds when appropriate.

Example use cases

  • CI job that builds and archives an iOS app: discover scheme, run xcodebuild archive with -archivePath.
  • Local development: run swift build and swift test for a cross-platform command-line Swift package.
  • Automated test runner: list schemes, build-for-testing, then xcodebuild test-without-building against an iPhone simulator.
  • Mixed project: find SPM targets exposed as schemes in an Xcode project and build a single library target without building the full app.
  • Troubleshooting: list available simulators with xcrun simctl and adjust -destination specifiers for flaky simulator selection.

FAQ

Can I use swift build for a Swift package embedded in an Xcode project?

No. swift build/test only works for standalone Package.swift repos. For packages embedded in Xcode, use xcodebuild with the package target's scheme.

What destination should I use for iOS device-less CI builds?

Use -destination 'generic/platform=iOS' for device-less builds, and provide a simulator spec for running tests.

How do I avoid code signing errors in CI?

For builds that don't require signing, set CODE_SIGNING_ALLOWED=NO or configure a provisioning profile and signing identity for signed archives.