To build iOS, macOS and watchOS from one Xcode project on a remote Mac, run xcodebuild build once per destination from a shell loop and print a pass or fail line for each. The loop below does that, with a separate derived-data folder per platform. Find your scheme names first with xcodebuild -list -workspace YourApp.xcworkspace.
How do I structure one project for three destinations?
Declare a minimum deployment version per platform in the Swift package manifest, and gate platform-only APIs behind #if os(...). Xcode honors the manifest versions for each destination:
// Package.swift
let package = Package(
name: "MySharedLib",
platforms: [
.iOS(.v16),
.macOS(.v13),
.watchOS(.v9),
]
)
import SwiftUI
struct HeartRateView: View {
var body: some View {
#if os(watchOS)
HeartRateSensor() // HealthKit live session
#elseif os(iOS)
HeartRateChart() // HealthKit history on iOS
#else
Text("Synced from your paired device.")
#endif
}
}
For a dependency that only makes sense on some platforms, attach a condition rather than wrapping the import in every file. The .when(platforms:) modifier is documented in Apple's PackageDescription reference:
.target(
name: "MyFeature",
dependencies: [
"SharedModels",
.product(name: "Analytics", package: "analytics-swift",
condition: .when(platforms: [.iOS, .macOS]))
]
)
How do I build every destination in one script?
Use the loop below. The destination syntax (platform=...,name=...,OS=...) is defined in Apple's TN2339 "Building from the Command Line with Xcode FAQ". Run it from the project root and replace the workspace and scheme names with your own.
#!/bin/zsh
# -e intentionally omitted so all three destinations run even if one fails.
set -uo pipefail
WORKSPACE="YourApp.xcworkspace"
IOS_SCHEME="YourApp"
MACOS_SCHEME="YourApp (macOS)"
WATCH_SCHEME="YourApp Watch App"
RESULT_FILE=$(mktemp "${TMPDIR:-/tmp}/build-summary.XXXXXX")
trap 'rm -f "$RESULT_FILE"' EXIT
run_build() {
local label="$1" scheme="$2" destination="$3"
echo "==> Building $label..."
if xcodebuild build \
-workspace "$WORKSPACE" \
-scheme "$scheme" \
-destination "$destination" \
-derivedDataPath "./DerivedData/$label" \
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO \
2>&1 | tee "./build_${label}.log" | tail -3; then
echo "$label: PASS" >> "$RESULT_FILE"
else
echo "$label: FAIL (see build_${label}.log)" >> "$RESULT_FILE"
fi
}
run_build "iOS" "$IOS_SCHEME" "generic/platform=iOS Simulator"
run_build "macOS" "$MACOS_SCHEME" "platform=macOS,arch=arm64"
run_build "watchOS" "$WATCH_SCHEME" "generic/platform=watchOS Simulator"
echo
echo "===== Build Summary ====="
cat "$RESULT_FILE"
Notes so the script matches reality:
- The code is an untested example, not a reported benchmark. Pipeline exit codes propagate through
teebecauseset -o pipefailis on. generic/platform=...compiles for the simulator SDK without booting a device. Switch toplatform=iOS Simulator,name=iPhone 16,OS=latestonly when a specific simulator is needed for tests.arch=arm64builds the macOS target for Apple silicon. On the Intel Mac VM substitutearch=x86_64; it cannot execute arm64 code.- For Mac Catalyst use
platform=macOS,variant=Mac Catalyst.
How do I test each target?
Run xcodebuild test per destination with real simulator names so the test runner boots:
xcodebuild test -workspace "$WORKSPACE" -scheme "YourApp" \
-destination "platform=iOS Simulator,name=iPhone 16,OS=latest"
xcodebuild test -workspace "$WORKSPACE" -scheme "YourApp (macOS)" \
-destination "platform=macOS,arch=arm64"
xcodebuild test -workspace "$WORKSPACE" -scheme "YourApp Watch App" \
-destination "platform=watchOS Simulator,name=Apple Watch Series 10 (46mm),OS=latest"
A failed xcodebuild test exits non-zero. Use set -e if you want the run to stop at the first failing platform, or keep the earlier loop pattern if you want every destination to report.
How much disk and memory does one session use?
Three clean builds of a mid-size app typically accumulate several GB of derived data. Keeping each platform under its own -derivedDataPath, as the loop does, stops a stale product on one platform from hiding a real error on another. Xcode already schedules independent targets in parallel within a scheme, so measure wall-clock time on your own project before paying for more RAM: memory contention and duplicated transitive dependencies often matter more than core count.
Can one Mac build iOS, macOS and watchOS targets together?
The Apple Silicon Mac VM ($39 a month, $6 a day, 4GB RAM) is the usual fit for iOS, macOS and watchOS builds on current Xcode. The Intel Mac VM ($25 a month) works only if Xcode 26.3 or earlier covers all your targets, since it runs macOS Sequoia and cannot run Apple silicon-only tools or visionOS. VM vCPUs are shared, so time your own project. Add the loop to a self-hosted runner on the Mac to catch cross-platform regressions on every push.
How does the price compare with another rental?
CloudMac publishes $99.99/month on an M4 with 16 GB RAM and 256 GB SSD, and its home page lists a $999/year option on the same base tier, which works out to $83.25/month effective. CloudMac's 512 GB and 1 TB rows currently show "Fully reserved, Next allocation not scheduled", so availability is per SKU.
Against Figment, 12 × $39 = $468 a year for the Apple Silicon Mac VM is $531 less than CloudMac's $999, but it is 4GB RAM and 4 shared vCPUs, not a whole Mac with 16GB. Figment's Dedicated M4 Pro 48 GB is a whole Mac (48GB RAM, 512GB SSD) at $3,228 a year paid up front, or 12 × $299 = $3,588 on a 12-month term. Compare on the specifications you need, and add tax as it appears at purchase.
Related guides: