SwiftUI is a good fit for an AI coding agent: views are small, declarative Swift files, and the compiler is strict enough to catch many mistakes. The weak spot is feedback. Without setup, Claude Code writes a view and has no idea whether it compiles or how it looks. This post fixes that.
1. Make the build run from the terminal
Claude Code works by running commands and reading the output, so give it commands. Start by finding your scheme and a simulator:
xcodebuild -list
xcrun simctl list devices available
Then a build and a test command for one simulator:
xcodebuild -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 16' build
xcodebuild -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 16' test
Use your own scheme and a simulator from the list. Run both once yourself so you know they work before you hand them over.
2. Write a CLAUDE.md for the project
Anthropic describes CLAUDE.md as the file “Claude Code reads at the start of every session.” For a SwiftUI app, include:
- the build and test commands above,
- the minimum iOS version, so it does not reach for APIs you cannot use,
- your state approach (for example
@Observablemodels owned by the view that needs them), - folder rules: one feature per folder, one view per file,
- “run the tests after every change and fix failures before moving on,”
- what it must not touch: signing settings, entitlements and the project file except to add files.
Run /init first to get a draft, then edit it. Keep it under the 200 lines the docs recommend. See CLAUDE.md for Flutter for the same idea in another stack.
3. Add an Xcode build MCP server
Raw xcodebuild output is long. An MCP server can give the agent cleaner tools. Sentry’s XcodeBuildMCP describes itself as “a Model Context Protocol (MCP) server and CLI that provides tools for agent use when working on iOS and macOS projects.” Its README lists macOS 14.5 or later and Xcode 16 or later, and gives an on-demand command (npx -y mobilebuildmcp@latest mcp; the project now also uses the name MobileBuildMCP). Using Claude Code’s documented syntax for a local server:
claude mcp add xcodebuild -- npx -y mobilebuildmcp@latest mcp
Check the project’s own client docs for the current snippet, and as Anthropic’s MCP page says, “verify you trust each server before connecting it.”
4. Package SwiftUI rules as skills
A skill is a SKILL.md that “loads only when it’s used,” so it can hold long reference material. Good SwiftUI skills:
- View standards: small views, previews for every state (loading, empty, error, full), Dynamic Type and Dark Mode checked.
- Accessibility: labels on icon buttons, 44-point touch targets, VoiceOver order.
- Persistence: how you use SwiftData or your storage layer, including migrations.
- Store rules: a pre-submission check for account deletion, in-app purchase and privacy. See the App Store submission checklist; most of it applies to native apps too.
Put them in .claude/skills/<name>/SKILL.md and commit them. How to write a Claude Code skill covers the format.
5. Keep these in Xcode
- Previews. Look at each view yourself. An agent cannot tell you whether spacing feels right.
- Signing and capabilities. Sign in with Apple, push and iCloud are set in Xcode and the developer portal.
- Archive and upload. Do these yourself or in CI. See TestFlight beta testing.
- Instruments. For memory and performance work, read the traces yourself and give Claude Code the findings.
A loop that works
- Ask for a plan for one feature, including each state of each view.
- Let Claude Code write the views and models and run the build and tests.
- Open the previews in Xcode and run on a simulator.
- Ask for fixes with specific notes (“the empty state has no call to action”).
- Review the diff, commit, repeat.
When to choose SwiftUI over a cross-platform stack
Choose SwiftUI if you only need iOS, want new Apple APIs on day one, or need widgets and system integrations to feel exact. If you also need Android, compare SwiftUI vs Flutter. The broader setup for every stack is in Claude Code for mobile app development.
Sources read on the day this post was written: Claude Code memory (CLAUDE.md), Claude Code skills, Claude Code MCP and XcodeBuildMCP on GitHub.