Skip to main content

Overview

The @Reducer macro is the primary way to define features in The Composable Architecture. It synthesizes the necessary boilerplate code to conform your type to the Reducer protocol, allowing you to focus on your feature’s logic. When applied to a type, the macro generates:
  • State and Action type definitions from nested types or enums
  • Protocol conformance to Reducer
  • Additional helper types for enum reducers like CaseScope
  • Protocol conformance to CaseReducer for enum reducers

Basic Usage

Apply the @Reducer macro to a struct that defines your feature:

Enum Reducers

The @Reducer macro also supports enum-based reducers for modeling navigation destinations or mutually exclusive states:
For enum reducers, the macro synthesizes additional helpers for scoping into each case.

Using with Dependencies

The @Reducer macro works seamlessly with the @Dependency property wrapper:

Using with ObservableState

Combine @Reducer with @ObservableState for SwiftUI observation:

Special Case Macros

When working with enum reducers, you can use additional macros to handle special cases:

@ReducerCaseEphemeral

Marks a case as holding ephemeral state like alerts or confirmation dialogs:

@ReducerCaseIgnored

Marks a case that holds plain data rather than a reducer feature:

See Also