Key takeaways
- CLAUDE.md must name your deployment target and the SwiftUI APIs to use and avoid in new code.
- Give Claude Code one build command and one test command with a simulator destination that exists on every Mac it runs on.
- The agent cannot see the preview canvas; tests and simulator screenshots are how it checks UI work.
- Since Xcode 26.3, Xcode exposes its tools over MCP, so Claude Code can connect to the IDE through xcrun mcpbridge.
- Commit a .claude/settings.json that pre-approves build commands and denies access to certificates, keys and entitlements.
Where SwiftUI trips up a coding agent
SwiftUI changes with every iOS release, and a model's training data mixes all generations of its APIs. Without guidance, four problems show up again and again:
- Mixed API generations.
NavigationViewnext toNavigationStack, orObservableObjectin a codebase that has moved to the@Observablemacro. - Concurrency friction. In Swift 6 language mode, UI state touched off the main actor stops compiling. The quickest agent fix – a blanket
@MainActoror an unchecked annotation – compiles but is not always right. - Target membership. In projects whose folders stay in sync with the file system, new files join their target automatically; with classic groups the agent must edit
project.pbxproj, which is fragile. - Invisible UI. The agent knows a view compiles, not that it looks right on a small iPhone in Dark Mode.
Your setup has to answer exactly these questions: which APIs, which concurrency rules, how files join targets, and how the agent sees what it built.
A CLAUDE.md written for a SwiftUI codebase
Claude Code reads CLAUDE.md at the start of every session. Run /init to get a draft, then cut it down and add the decisions the agent cannot infer from the code. A compact example for a single-target app:
# Recipes – notes for Claude Code
## Build and test
- Scheme: Recipes
- Build: xcodebuild -scheme Recipes -destination 'platform=iOS Simulator,name=iPhone 17' -derivedDataPath build/dd build -quiet
- Test: xcodebuild -scheme Recipes -destination 'platform=iOS Simulator,name=iPhone 17' -derivedDataPath build/dd test -quiet
- A task is finished when the test command passes. If it fails, report the failing test by name.
## Swift and SwiftUI rules
- Deployment target iOS 17. New code uses NavigationStack and @Observable – no NavigationView, no ObservableObject.
- Swift 6 language mode. Fix concurrency errors at the source; ask before adding @unchecked Sendable or nonisolated(unsafe).
- One view per file in Features/<Feature>/. Views stay thin; logic lives in the feature's model type.
- Every control gets an accessibility label. Support Dynamic Type; no fixed font sizes.
- User-facing strings go into Localizable.xcstrings.
## Ask before changing
- Recipes.entitlements, Info.plist usage descriptions, PrivacyInfo.xcprivacy
- Signing settings, bundle identifier, team, build configurations
- Package.resolved – no new Swift packages without approval
The simulator in the destination must exist on every Mac that runs the agent (xcrun simctl list devices available shows what is installed). A local -derivedDataPath keeps build products and logs inside the project, where the agent finds them; add build/ to .gitignore.
If you maintain instructions for several agents, our guide to CLAUDE.md and AGENTS.md for mobile projects shows how to share one file between tools.
Talk to an AI Code Engineer about shipping your app to the App Store.
In a free call we look at what you built, tell you honestly what stands between it and an approved release – and whether you need us at all.
The build–test loop: let the compiler and the simulator answer back
The pattern that works is unexciting: plan, implement one small step, build, test, read the errors, repeat. Ask for it explicitly:
Add a favorites filter to the recipe list. Plan first and wait for my OK. Then implement in small steps; after each step run the build command from CLAUDE.md, and finish only when the test command passes.
Use plan mode for anything that touches more than one feature. Reading a plan takes a minute; unpicking the wrong architecture across a dozen files takes an afternoon.
-quiet reduces xcodebuild output to warnings and errors; a formatter such as xcbeautify shortens it further (use set -o pipefail so a failed build still fails). Shorter logs leave the agent's context for the actual error.
For UI work, give the agent eyes:
- Unit tests for model types. Most SwiftUI bugs live in state handling, which can be verified without a screen.
- Snapshot tests. With a snapshot testing library, layout regressions become failing tests the agent can read.
- Simulator screenshots.
xcrun simctl io booted screenshot shot.pngcaptures the running simulator. Claude Code reads images, so it can compare the screen with your request – or with a design export you put into the repository.
Once the loop works interactively, the same commands run headless with claude -p in a script or CI job – keep such runs small enough to review in one sitting.
Connecting Claude Code to Xcode itself
Shell commands cover building and testing. Since Xcode 26.3, Xcode also exposes its own capabilities over the Model Context Protocol through a bridge in its command line tools, so an external agent can work with the project the way Xcode sees it. Adding it to Claude Code is one command:
claude mcp add --transport stdio xcode -- xcrun mcpbridge
Expect Xcode to ask for permission when a new agent process connects; the agent features need macOS 26. The open-source XcodeBuildMCP project is an alternative that wraps xcodebuild, simctl and simulator control in structured tools. Both are optional: start with plain commands and add a server when the agent struggles with raw output. Our overview of MCP servers for iOS and Android development compares the options and their risks.
Xcode 26.3 also has agentic coding built in, with Claude Agent and Codex as providers. Many developers use both: the built-in agent for quick edits, Claude Code in the terminal for longer tasks involving git, scripts and CI. Claude Code vs. Cursor for iOS apps discusses how editor and terminal agents divide the work.
Prompt patterns for typical SwiftUI tasks
Good prompts for Swift work name the input the agent needs and the evidence you expect back:
| Task | Give Claude Code | Ask for this evidence |
|---|---|---|
| New screen | A sketch or screenshot, the model type, where it is reached from | Passing build, screenshots in light and dark mode and at a large text size |
Migration to @Observable | The affected files and the migration rule | Tests unchanged and green, diff limited to the listed files |
| Layout bug | Screenshot of the bug, device, orientation | A screenshot after the fix on the same simulator |
| Concurrency error | The full compiler error and which actor owns the state | A fix without new unchecked annotations, or a reason why one is needed |
Point at existing code: "follow the pattern in SettingsView.swift" conveys your conventions faster than a paragraph of rules. For larger changes, a read-only review subagent can check the diff against CLAUDE.md before you do.
Guardrails: permissions and hooks for an iOS repository
Claude Code asks before it runs commands or edits files unless you have allowed them. In an iOS project, pre-approve the routine commands and block the sensitive files in .claude/settings.json, which you commit so the whole team shares the same rules:
{
"permissions": {
"allow": [
"Bash(xcodebuild:*)",
"Bash(xcrun simctl:*)",
"Bash(git diff:*)"
],
"deny": [
"Read(**/*.p12)",
"Read(**/*.p8)",
"Read(**/*.mobileprovision)",
"Edit(**/*.entitlements)"
]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "./scripts/format-edited-swift.sh" }]
}
]
}
}
The hook receives the edit details as JSON on standard input, so a small script can run swift-format on just the changed file.
Better still, keep certificates and API keys out of the repository: signing identities belong in the keychain or CI secrets. Skip the permission-bypass flag on the Mac that holds your Apple account; give long unattended runs a separate macOS user or a dedicated build Mac. The security risks of agentic coding article covers this in depth.
From working code to a TestFlight build
A green test run is not a release. The first upload needs an App Store Connect record, signing that works beyond your own Mac, a privacy manifest that matches your SDKs, and an archive built with Xcode 26 and the iOS 26 SDK. Claude Code can prepare fastlane lanes, build number bumps and a macOS CI workflow; the account decisions stay with you. The full walkthrough is in Claude Code app to the App Store.
Two ways we help: our AI Code Engineers run hands-on Claude Code workshops on your own codebase, and through the iOS submission service they take over signing, CI/CD and the submission in your own Apple Developer account.
Claude Code SwiftUI setup checklist
- CLAUDE.md names the scheme, a simulator destination that exists on every Mac, and one build and one test command.
- Deployment target, navigation and state APIs are written down, including what to avoid in new code.
- Concurrency rules say when unchecked annotations are acceptable – and that the agent asks first.
- The agent can see UI results through simulator screenshots or snapshot tests.
- .claude/settings.json allows routine build commands and denies certificates, keys and entitlements.
- Signing identities live in the keychain or CI secrets, never in the repository.
Frequently asked questions
Does Claude Code work with Xcode projects or only with Swift packages?
Both. Claude Code edits files on disk and drives builds through xcodebuild, so classic Xcode projects work fine. Projects whose folders stay in sync with the file system are easier, because new files join their target without edits to project.pbxproj.
Can I use Claude Code for an iOS app on Linux or Windows?
Claude Code runs there and can edit Swift code, but it cannot build, test or archive the app: that needs Xcode on macOS. Use a Mac for the build–test loop, or let a macOS CI runner verify every pull request.
Should I use Claude Code or the agent built into Xcode 26.3?
They complement each other. The built-in agent is convenient for quick changes while you work in the IDE. Claude Code in the terminal suits longer tasks that combine code, git, scripts and CI – and it can connect to Xcode through xcrun mcpbridge.
Can you help our team set this up?
Yes. Book a free call with an AI Code Engineer. We can set up the memory file, permissions and build loop with your team in a workshop, or take your app from repository to App Store release.
Free, 15 minutes, no obligation
Get your app from agent output to approved release.
Our AI Code Engineers take apps built with Claude Code, Codex, Cursor, Lovable, Base44 and co. through signing, CI/CD, store listings and review – in your own developer accounts.
AI tools, store policies and requirements change quickly – always check the current documentation of the tools and stores you use. This article is independent advice and not affiliated with or endorsed by Apple, Google, Anthropic, OpenAI or any other company or product mentioned; all trademarks belong to their owners.