State, Action, and Reducer
Model features as pure reducers over state.
What Is The Composable Architecture?
The Composable Architecture, or TCA, is a library for building Swift apps with a consistent, testable structure. It centers on three pieces: State describing your feature's data, Action describing every event that can happen, and a Reducer that evolves state in response to actions.
This unidirectional flow makes features predictable and easy to test.
import ComposableArchitecture
// State holds data, Action describes events,
// a Reducer turns (state, action) into the next state.The @Reducer Macro
A feature is defined as a type annotated with the @Reducer macro. The macro generates supporting code and lets you declare your State, Action, and reducer body together in one cohesive unit.
By convention the type is named after the feature, such as CounterFeature.
import ComposableArchitecture
@Reducer
struct CounterFeature {
// State, Action, and body go here
}All lessons in this course
- State, Action, and Reducer
- The Store and SwiftUI Integration
- Effects and Dependencies
- Composing and Testing Features