hocgin/agent-skills/swift-composable-architecture
Claude Code and agent skill by hocgin/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Use when building, refactoring, debugging, or testing iOS/macOS features using The Composable Architecture (TCA). Covers feature structure, effects, dependencies, navigation patterns, and testing with TestStore.
Install
npx vskill@latest install hocgin/agent-skills/swift-composable-architectureSKILL.md
The same SKILL.md was published earlier as hocgin/agent-skills/swift-composable-architecture.
You are an expert in The Composable Architecture (TCA) by Point-Free. Help developers write correct, testable, and composable Swift code following TCA patterns.
Core Principles
- Unidirectional data flow: Action → Reducer → State → View
- State as value types: Simple, equatable structs
- Effects are explicit: Side effects return from reducers as
Effectvalues - Composition over inheritance: Small, isolated, recombinable modules
- Testability first: Every feature testable with
TestStore
The Four Building Blocks
- State – Data for UI and logic (
@ObservableState struct) - Action – All events: user actions, effects, delegates (
enumwith@CasePathable) - Reducer – Pure function evolving state, returning effects (
@Reducer macro) - Store – Runtime connecting state, reducer, and views (
StoreOf<Feature>)
Feature Structure
Effects
| Pattern | Use Case | |
|---|---|---|
.none | Synchronous state change, no side effect | |
.run { send in } | Async work, send actions back | |
.cancellable(id:) | Long-running/replaceable effects | |
.cancel(id:) | Cancel a running effect | |
.merge(...) | Run multiple effects in parallel | |
.concatenate(...) | Run effects sequentially |
Cancellation
cancelInFlight: true auto-cancels previous effect with same ID.
Dependencies
Built-in Dependencies
@Dependency(\.uuid), @Dependency(\.date), @Dependency(\.continuousClock), @Dependency(\.mainQueue)
Custom Dependencies
- Define client struct with closures
- Conform to
DependencyKeywithliveValue,testValue,previewValue - Extend
DependencyValueswith computed property - Use
@Dependency(\.yourClient)in reducer
Test override: withDependencies { $0.apiClient.fetch = { .mock } }
Composition
Child Features
Use Scope to embed children:
View: ChildView(store: store.scope(state: \.child, action: \.child))
Collections
Use IdentifiedArrayOf<ChildFeature.State> with .forEach(\.items, action: \.items) { ChildFeature() }
Navigation
Tree-Based (sheets, alerts, single drill-down)
- Model with optional state:
@Presents var detail: DetailFeature.State? - Action:
case detail(PresentationAction<DetailFeature.Action>) - Reducer:
.ifLet(\.$detail, action: \.detail) { DetailFeature() } - View:
.sheet(item: $store.scope(state: \.detail, action: \.detail))
Stack-Based (NavigationStack, deep linking)
- Model with
StackState<Path.State>andStackActionOf<Path> - Define
@Reducer enum Path { case detail(DetailFeature) ... } - Reducer:
.forEach(\.path, action: \.path) - View:
NavigationStack(path: $store.scope(state: \.path, action: \.path))
Delegates
Child emits delegate actions for outcomes; parent responds without child knowing parent's implementation.
Testing
TestStore Basics
Key Patterns
- Override dependencies - never hit real APIs in tests
- Assert all state changes - mutations in trailing closure
- Receive all effects - TestStore enforces exhaustivity
- TestClock - control time-based effects with
clock.advance(by:) - Integration tests - test composed parent+child features together
Higher-Order Reducers
For cross-cutting concerns (logging, analytics, metrics, feature flags):
Modern TCA (2025+)
@Reducermacro generates boilerplate@ObservableStatereplaces manualWithViewStore@CasePathableenables key path syntax for actions (\.action.child)@Dependencywith built-in clients (Clock, UUID, Date)@MainActoron State when SwiftUI requires it- Direct store access in views (no more
viewStore)
Critical Rules
DO:
- Keep reducers pure - side effects through
Effectonly - Use
IdentifiedArrayfor collections - Test state transitions and effect outputs
- Use delegates for child→parent communication
DO NOT:
- Mutate state outside reducers
- Call async code directly in reducers
- Create stores inside views
- Use
@State/@StateObjectfor TCA-managed state - Skip receiving actions in tests
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/swift-composable-architecture /SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hocgin/agent-skills/swift-composable-architecture)