Is TCA the ultimate architecture for AI agent development in iOS apps?
Why a strict architecture with compiler checks and TestStore is the best feedback loop for AI. Part 1 of 2.
By Dmitrii Cherviakov · Senior iOS Developer
This is part one of two. In part two I cover skills, rules and lessons learned on a real project.
Have you tried vibe coding an app, handing all of the code writing to an AI agent? The first features show up amazingly fast. Then something shifts: every new feature or bug fix breaks something somewhere else, and bugs pop up in code nobody touched. Then tech debt piles up, and you especially don't want to dig into it, because that code was generated, not written by you.
That led me to a simple idea: AI development works well with architectures that have strict rules and compile-time checks. Architectures where the agent learns about a mistake from the compiler or a test, not from a user a week later. Then the code comes out safe, maintainable, scalable and testable, even if almost all of it was written by something other than a human.
For the last two years I have been building a production app on The Composable Architecture (TCA) and using agentic development heavily. Below are my impressions, the pros and the cons.
TCA today: a different TCA
If you looked at TCA two years ago, it is in many ways a different library now. Especially since Apple shipped the Observation framework in iOS 17: feature state became a plain struct with @ObservableState, and the view reads it directly, without WithViewStore and ViewStore. The @Reducer macro removed most of the boilerplate, and navigation with @Presents and StackState became declarative.
Many people remember TCA for its early problems: slowdowns with large state, verbosity, complicated navigation. Most of that has been solved, and version 2.0 is already in private beta for Point-Free subscribers. All the examples in this article are written against the current stable 1.x branch.
One caveat up front: the learning curve has not gone anywhere. TCA is built on unidirectional data flow, and if you aren't familiar with that concept yet, you'll have to change your picture of how an app works a bit: think in terms of state, actions and effects. The first few weeks feel unusual.
My path with TCA
I have followed this architecture for a long time and have been working with it for several years. First I wrote a few pet projects with it, I liked it, and when I joined a new project where the app was being built from scratch, I brought TCA into production.
After two years of production experience I still like it. I have never hit its limits. For pet projects and small apps it is a convenient and reliable foundation.
My path with AI
I have been working with AI in one way or another for a long time. At one point I shipped an app with on-device image generation, built on CoreML. Gradually I added GPT to my workflow. I started with simple cases, like automating the rewrite of XIBs into layout in code. Even GPT-3.5 could handle that.
And of course, with the arrival of agentic development (Claude Code in particular) and models at the Opus level, I started using agents at work. At first I generated views from detailed descriptions, added new endpoints, changed existing code, asked for advice and looked for ways to optimize. The scope grew along with the models, and now the agent can build entire features.
In my opinion, the most important thing for developing effectively with AI is building a proper feedback loop. Gathering context to start working on a feature is basically solved already: there are MCPs for Confluence and Jira, and designs come out of Figma through MCP as well. I wrote more about that part in the post where I measured my speed.
The most interesting and hardest part turned out to be validating what was written. And it has to be set up so the agent gets feedback as fast as possible, fixes itself, and after a few iterations delivers a finished feature.
The first level of feedback: the compiler
The first part of that feedback loop is compile errors. And this is where TCA has a serious advantage.
Take MVVM. Every company, and even every team, decides in its own way how to write view models. Sure, everyone uses linters to keep the code in one style. But a linter catches mistakes later, and it mostly checks style, not architectural agreements. A compile error gives feedback earlier: the agent gets it as soon as it builds its code.
In TCA the rules of the architecture are expressed in types, and the compiler checks them on its own. Here is a simplified version of a real feature, the dialog for reporting content:
@Reducer
struct ComplainFeature {
@ObservableState
struct State: Equatable {
let contentID: Int
var isSubmitting = false
}
enum Action {
case complainResponse(Result<Void, any Error>)
case submitButtonTapped
}
@Dependency(\.networking) var networking
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .complainResponse:
state.isSubmitting = false
return .none
case .submitButtonTapped:
state.isSubmitting = true
return .run { [id = state.contentID] send in
await send(.complainResponse(Result {
try await networking.complain(id)
}))
}
}
}
}
}What matters here for the agent:
- Everything that can happen is listed in
Action. Theswitchis exhaustive: if you add a new case and forget to handle it, the code won't compile. - State changes only in the reducer. There aren't five places where someone quietly flips a flag, so a change doesn't "leak" into a neighboring feature.
- Side effects are explicit. Networking goes only through
@Dependency, and async work is returned from the reducer as.run. The compiler won't stop you from firing a request right in a view'sonAppear, but by the pattern a request doesn't belong there, and that kind of bypass of the reducer stands out right away in review.
Each of these rules is a constraint. For a human it is sometimes bureaucracy. For an agent it is rails: it generates code from a known template, and the compiler immediately tells it where it went off them.
The second level: unit tests
The next step after writing and compiling is unit tests. They are fast, easy to run after every change, and they can cover all of the logic. UI runs in the simulator are needed too, but those take minutes per scenario, while a unit test takes seconds.
This is where one of TCA's biggest strengths shows up: the architecture was designed from the start with attention to testing and to how easy the code is to test.
TestStore: an exhaustive test
Here is a test for the same feature:
@MainActor @Test func submitSendsComplaint() async {
let contentID = 7
let store = TestStore(initialState: ComplainFeature.State(contentID: contentID)) {
ComplainFeature()
} withDependencies: {
$0.networking.complain = { id in #expect(id == contentID) }
}
await store.send(.submitButtonTapped) {
$0.isSubmitting = true
}
await store.receive(\.complainResponse) {
$0.isSubmitting = false
}
}By default TestStore is exhaustive. It requires you to describe every state change after every action and to accept, via receive, every action that comes back from an effect. If the agent changed something extra in the reducer (say, forgot to reset isSubmitting, or added a new action to the chain), the test fails even if the "main" assertion passed.
And, more importantly, it fails with a clear message. This is what the failure looks like if isSubmitting wasn't reset:
A state change does not match expectation.
ComplainFeature.State(
contentID: 7,
− _isSubmitting: false
+ _isSubmitting: true
)
(Expected: −, Actual: +)That is basically a ready-made prompt: which action, which field, what was expected and what actually happened. The agent doesn't have to guess anything: it reads the diff, fixes the reducer and reruns the test. That short loop is exactly what turns "generated code" into "a working feature".
Dependencies: no silent networking in tests
The third building block is dependencies. Here is the haptic feedback client in full:
@DependencyClient
struct HapticClient: Sendable {
/// `UINotificationFeedbackGenerator(.success)`: the green success popup.
var success: @Sendable () async -> Void
}
extension HapticClient: DependencyKey {
static var liveValue: Self {
Self(
success: {
// UINotificationFeedbackGenerator is @MainActor: hop to main explicitly from .run.
await MainActor.run {
UINotificationFeedbackGenerator().notificationOccurred(.success)
}
}
)
}
// In tests, every method the test didn't override fails as unimplemented.
static var testValue: Self { Self() }
}
extension DependencyValues {
var haptic: HapticClient {
get { self[HapticClient.self] }
set { self[HapticClient.self] = newValue }
}
}Reducers never touch UIKit directly, only @Dependency(\.haptic). In a test that cares about haptics, the client is replaced with a counter: $0.haptic.success = { haptics.withValue { $0 += 1 } }.
The key property for working with an agent: any @DependencyClient method the test didn't override fails as unimplemented. If the agent added a new request to a feature and didn't account for it in the test, the test won't silently pass through the real network. It fails and names the exact method. Annoying in the moment, priceless in the long run: every new interaction with the outside world has to end up in a test.
Part one, wrapped up
Code written with an agent doesn't degrade because the agent writes badly. It degrades because the agent has nothing to lean on: no rules it can't break, and no fast way to find out it broke something. TCA closes both gaps:
- the rules are built into the architecture and checked by the compiler: exhaustive
switch, explicit effects, typed dependencies; - the exhaustive
TestStoreturns every mistake into a precise diff the agent uses to fix itself.
In part two I show what this looks like in practice: why LLMs don't know TCA well and what to do about it, the rules from the project's memory, the pitfalls the agent ran into, and what happens to code quality as the app grows.