Build, test, launch and screenshot an iOS app on a Mac with Xcode. Use when a task asks to compile an Xcode project or Swift package for iOS, run unit or UI tests on an iOS Simulator, reproduce a crash, check a screen visually, or attach Simulator screenshots and test results to a pull request. Works on a local Mac or a hosted Mac such as a Macswarm Pod.
npx mdskills install MacSwarm/ios-build-and-testRelated
1---2name: ios-build-and-test3description: Build, test, launch and screenshot an iOS app on a Mac with Xcode. Use when a task asks to compile an Xcode project or Swift package for iOS, run unit or UI tests on an iOS Simulator, reproduce a crash, check a screen visually, or attach Simulator screenshots and test results to a pull request. Works on a local Mac or a hosted Mac such as a Macswarm Pod.4---56# Build and test iOS on a Mac78You are on macOS with Xcode installed. Prove changes on a Simulator before you call a task done: a green build is not a passing test, and a passing test is not a screen anyone has looked at.910## 1. Check the machine1112```bash13sw_vers -productVersion14xcodebuild -version15xcrun simctl list runtimes available16```1718If `xcodebuild` is missing, stop and report it. Do not install Xcode yourself.1920If an XcodeBuildMCP server is connected, you may use its build, test, launch and screenshot tools instead of the commands below. The steps and the evidence you collect stay the same.2122## 2. Find the project, scheme and destination2324```bash25ls *.xcworkspace *.xcodeproj Package.swift 2>/dev/null26xcodebuild -list -json # add -workspace X.xcworkspace or -project X.xcodeproj27xcrun simctl list devices available --json28```2930- Prefer the `.xcworkspace` when one exists (CocoaPods and multi-project setups need it).31- Use the scheme named in the repository's `AGENTS.md` or `CLAUDE.md`. If none is named and there is more than one app scheme, ask before guessing.32- Pick a Simulator by UDID, not by name, so the command does not depend on which device models are installed. Prefer one that is already `Booted`.3334Store the choices once for the session:3536```bash37WS="-workspace App.xcworkspace" # or PROJ="-project App.xcodeproj"38SCHEME="App"39UDID="<udid from simctl>"40DEST="platform=iOS Simulator,id=$UDID"41```4243## 3. Build4445```bash46xcodebuild $WS -scheme "$SCHEME" -destination "$DEST" \47 -derivedDataPath .build/DerivedData build 2>&1 | tail -n 8048```4950Read the first `error:` line, not the last one. Fix the cause and rebuild. Never commit with a failing build.5152On a shared Mac, builds may queue behind other agents. Keep working on something that does not need the compiler while you wait; do not start a second build of the same scheme.5354## 4. Test5556```bash57xcodebuild $WS -scheme "$SCHEME" -destination "$DEST" \58 -derivedDataPath .build/DerivedData \59 -resultBundlePath .build/Results.xcresult test 2>&1 | tail -n 8060xcrun xcresulttool get test-results summary --path .build/Results.xcresult61```6263- Run only the affected tests first with `-only-testing:Target/Class/testName`, then the full suite before you open a PR.64- When a test fails, quote the failing test name and its assertion message in your report.65- Delete `.build/Results.xcresult` before rerunning; `xcodebuild` refuses to overwrite it.6667## 5. Launch and look6869```bash70xcrun simctl boot "$UDID" 2>/dev/null || true71APP=$(find .build/DerivedData/Build/Products -name "*.app" -path "*iphonesimulator*" | head -n 1)72BUNDLE_ID=$(/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' "$APP/Info.plist")73xcrun simctl install "$UDID" "$APP"74xcrun simctl launch --console-pty "$UDID" "$BUNDLE_ID" &75sleep 576mkdir -p .build/screens77xcrun simctl io "$UDID" screenshot ".build/screens/01-launch.png"78```7980- Take one screenshot per screen you changed, numbered in the order a user reaches them.81- For crashes, collect the log: `xcrun simctl spawn "$UDID" log show --last 5m --predicate "process == \"$SCHEME\""`.82- Reset state between runs with `xcrun simctl uninstall "$UDID" "$BUNDLE_ID"` rather than erasing the device, which other agents may be using.8384## 6. Report8586Your final message and the PR description include:87881. The scheme, the Simulator (model and iOS version) and the Xcode version.892. Build result, and test totals from the `xcresulttool` summary.903. The screenshots, attached or committed under a path the reviewer can open.914. Anything you could not verify, stated plainly.9293Do not commit `.build/`. Add it to `.gitignore` if it is missing.94
Full transparency — inspect the skill content before installing.