Skip to main content
SwitchStore is deprecated. Use Swift’s native switch statement with observable state instead. See the migration guide for more information.
SwitchStore was a SwiftUI view used to switch over enum state and render different views for each case. Modern TCA allows you to use Swift’s native switch statement directly.

Declaration

Overview

SwitchStore was designed to work with enum-based state to show different views depending on which case is active. It worked in conjunction with CaseLet to extract associated values and scope the store.

Legacy Usage (Deprecated)

With @ObservableState, use Swift’s native switch statement:

Parameters

Legacy SwitchStore Parameters

  • store: The store containing enum state
  • content: A view builder that switches over the state and returns appropriate views

Migration Guide

Step 1: Add @ObservableState

Ensure your state enum has the @ObservableState macro:

Step 2: Replace SwitchStore with switch

Replace SwitchStore with a native Swift switch:

Step 3: Remove CaseLet

Replace CaseLet with optional binding and store.scope:

Working with Optional State

For optional enum cases, combine switch with if let:

Benefits of Migration

  • Native Swift: Use familiar switch syntax instead of custom views
  • Better Performance: Less view overhead
  • Type Safety: Compiler-enforced exhaustiveness checking
  • Simpler Code: Fewer custom types to learn
  • Better Debugging: Standard Swift control flow

See Also

  • @ObservableState: Makes state observable using Swift’s Observation framework
  • Store.scope: Transforms a store to work with child state and actions
  • ifCaseLet: Reducer operator for handling enum cases
  • Migration Guide