r/iOSProgramming • u/Iron-Ham • Mar 20 '26
Article How I got an AI coding agent to actually respect our iOS architecture (instead of just writing valid Swift)
I've been using Claude Code on a modular iOS app and wanted to share what I found, since most of the AI-for-code content I see is web-focused.
Without any project-specific guidance, the agent writes Swift that compiles but ignores everything about how the project is actually structured. It'll call xcodebuild raw with wrong flags, put business logic in views, use Color.blue instead of our design tokens, and reinvent patterns that already exist in other modules.
The thing that surprised me most was how much of the fix was about tooling, not documentation.
We have a verification skill that the agent runs after making changes. It builds the app, launches a simulator via XcodeBuildMCP, captures screenshots at key flows, runs an accessibility audit against WCAG 2.1 AA, and produces a structured pass/fail report. Before this existed, code review was the only safety net. Now the agent catches its own visual regressions and accessibility violations before I even look at the PR.
The other piece that made a big difference was design token enforcement. I maintain a TOKENS.md file that the agent reads at session start listing every color, spacing value, and text style. But docs alone weren't enough. I added custom SwiftLint rules that fail the build on Color literals and inline padding values. The design system injects through @Environment(\.appTheme), and now the agent proposes UI that matches our system by default rather than by accident.
The documentation layer matters too (I use a three-tier AGENTS.md hierarchy), but honestly the Makefile wrapping xcodebuild and the verification skill did more for output quality than any amount of written guidance.
I wrote up the full approach with implementation order and links to open-source skills (deep-review for code review, split for breaking branches into stacked PRs): https://sundayswift.com/posts/preparing-ios-codebase-for-ai-agents/
Curious if anyone else has tried structuring their iOS projects to work better with coding agents, or if you've found a completely different approach.
59
u/cristi_baluta Mar 20 '26
After reading for few minutes i want to abandon the ship and pick up farming
1
u/tanmaynargas2901 Mar 21 '26
Interesting. I just added a bunch of skills that help claude code understand the Swift documentation, and then also maintain the brand guidelines so when I request for new features, it does not hallucinate.
1
u/maaya_yu Mar 21 '26
Thanks for sharing !
1
u/Infinite_Button5411 Mar 22 '26
Exactly what we are working on in my team. Tokens.md is good idea for DS. Will try it out. Thanks for sharing.
1
u/seperivic Mar 22 '26
How do you structure your tokens for use, out of curiosity? Like what does an example call site look like for color or spacing values?
1
u/Money_Explorer747 Mar 26 '26
If the model is just generating code from a prompt, it usually ignores the actual structure of the project. But once you add architecture constraints and verification around the output, it becomes much more usable.
1
u/Deep_Ad1959 Mar 21 '26
the build-time enforcement part is what makes this work. had the same problem on a macOS app in swift - detailed markdown spec for the agent, but it kept using Color literals and inline padding. once I added lint rules that actually fail the build on those patterns, it started using the design system correctly on first try instead of needing multiple review rounds. docs are suggestions, compiler errors are requirements. biggest single change I've made for output quality.
-6
u/CaffeinatedMiqote Mar 21 '26 edited Mar 21 '26
How about actually open Xcode and type? No? Too much work for the ai bro and your rtx 5090?
-3
u/seweso Mar 21 '26
Why use ai agents to begin with? Why?