sundayswift.com

Preparing Your

iOS Codebase
for AI Agents

Documentation, tooling, and skills for agent-friendly development

Hesham Salman

The Problem

What happens when an agent has no context

  • Uses XCTest instead of Swift Testing
  • Calls xcodebuild with wrong flags
  • Ignores your TCA architecture entirely
  • Puts files in the wrong directories

The agent isn't dumb.
It just doesn't have your context.

The Three Layers

Each layer builds on the previous

1. Documentation
AGENTS.md hierarchy. The operating contract.
2. Tooling
Makefile + worktrees. The executable interface.
3. Skills
Executable methodology. The how-to guides.

Hierarchical AGENTS.md

Three levels of context, from broad to specific

Root
The team handbook. Naming conventions, VCS workflow, testing philosophy, troubleshooting guides.
Subsystem
The iOS playbook. Build commands, architecture decisions, banned patterns, platform-specific conventions.
Module
Tribal knowledge. Gotchas only someone working in this directory would know. The things you'd tell a new teammate.

Key principle: The subsystem refines, not replaces, the root.

Keep It Lean

More docs does not mean better docs

800 lines
first draft
415 lines
after trimming
Shorter docs = more effective. Every redundant line pushes actual code out of the context window.

How to Trim

Four rules for keeping docs lean

1. Remove anything derivable from code

2. Remove anything already in the root

3. Extract reference material, keep the rule inline

4. Replace directory trees with tables

Treat docs like code. An accessibility section went from 120 lines to 2 lines plus a link. Same information, 98% less context consumed.

Give Your Agents a Makefile

Agents can't click Cmd+B

make build            # Build the Prod variant
make test             # Run all tests
make test FILTER=…    # Filter to specific tests
make format           # Run SwiftFormat
make modules          # List all SPM modules
make setup            # First-time project setup

Each command encodes the correct flags, simulators, and sequencing.
Miss one flag and you get a cryptic error 3 minutes into a build.

The Makefile IS the institutional knowledge. Which scheme, which simulator, which derived data path, which Swift flags. All encoded once, used everywhere.

Block Direct Access

Wrapping isn't enough. You need a blocklist.

## IMPORTANT: Always Use Makefile Commands

**Do NOT call these tools directly:**
- `xcodebuild`  → use `make build` or `make test`
- `tuist build`  → use `make build`
- `tuist test`   → use `make test`
- `tuist install` → use `make install`

Without blocklist

Agent calls xcodebuild directly

Wrong flags, wrong simulator

Cryptic error, 5 minutes wasted debugging

With blocklist

Agent uses make build

Correct flags every time

Just works

The blocklist makes the Makefile the path of least resistance. Don't rely on the agent choosing the right tool. Remove the wrong tools from its vocabulary.

Worktree-Aware Tooling

Parallel agents need isolated environments

# Dynamic simulator per worktree
SIMULATOR = $(shell ./Tools/simulator-clone.sh get \
    2>/dev/null || echo "$(BASE_SIMULATOR)")

# Project-local DerivedData
DERIVED_DATA = $(PWD)/.build/DerivedData

1. Each worktree gets its own cloned simulator

2. DerivedData stays project-local, no cross-contamination

3. make build works identically in every worktree

Invisible to the agent. It runs make build and it just works. The isolation is handled by the Makefile, not by the agent.

Skills: Executable Methodology

Documentation tells agents WHAT. Skills tell them HOW.

1 Research Read the implementation and understand the domain
2 Analyze gaps Find coverage gaps and untested paths
3 Find examples Locate similar tests in the codebase as templates
4 Write tests Follow templates, use DI, match project conventions
5 Verify Run make test and fix any failures
6 Review Check quality, naming, and coverage completeness

Without the skill: agents use XCTest instead of Swift Testing, skip DI, and reinvent mock setup that already exists.

Design System Compliance

Make the design system the only practical way to style UI

@Environment(\.appTheme) private var theme

Text("Hello")
    .themeForeground(.primary)
    .themePadding(.md)
    .themeCornerRadius(.lg)

1. Token protocols define every visual property: colors, spacing, radii, typography, shadows

2. Convenience modifiers accept semantic levels, not raw values

3. TOKENS.md documents every token with correct/incorrect examples

4. Lint rules flag violations; make build runs them as errors, not warnings

5. Preview + snapshot tests verify the output visually

Three layers of enforcement. The API makes the right approach easy. Lint rules make the wrong approach a build failure. Previews catch everything else.

Visual Verification

Compiling is not the same as working

1 Screenshot Capture the screen to see what's rendered
2 View hierarchy Snapshot the element tree for structure analysis
3 Capture logs Check for runtime errors and warnings not visible in the UI
<!-- Simplified view hierarchy snapshot -->
<AXElement type="button" label="Submit" enabled="true">
  <AXElement type="text" value="Submit Order" />
</AXElement>
<AXElement type="image" label="" enabled="true" />  ⚠️ Missing label!

Side effect: missing accessibility labels fail the verification.

The agent reviews evidence, not just compilation. Observe, don't tap. Built on XcodeBuildMCP.

Self-Maintaining Docs

The feedback loop that keeps documentation honest

"AGENTS.md files are living documents. Update them when you discover undocumented conventions, encounter patterns not covered by existing guidance, or find that current instructions lead to mistakes."

The guardrail: Every change must leave the document shorter or more useful.

Docs stay current because the entities reading them are also updating them. Unlike human documentation that gets written once and slowly drifts, agent documentation evolves with every session.

Takeaways

Context > capability.
Agents are only as good as the context you give them. An agent with good docs, a Makefile, and skills outperforms a "smarter" agent that's flying blind.
Make the right approach the easy approach.
Blocklists, skills, templates. Don't fight the agent's defaults; redirect them. When the correct workflow is also the path of least resistance, the agent follows it naturally.
Documentation is infrastructure.
Unlike human docs that get read once, agent docs get read at the start of every session. It's the highest-leverage investment you can make in your agent workflow.