Skip to main content
WithViewStore is deprecated. Use @ObservableState instead for better performance and simpler code. See the migration guide for more information.
WithViewStore was a SwiftUI view that allowed you to observe store state changes and build UI that reactively updates. It has been superseded by Swift’s Observation framework and the @ObservableState macro.

Declaration

Overview

WithViewStore transformed a Store into a ViewStore, which was an ObservableObject that SwiftUI could observe. This pattern is no longer necessary with modern TCA and Swift’s Observation framework.

Legacy Usage (Deprecated)

With @ObservableState, you can directly access store state without WithViewStore:

Parameters

Legacy WithViewStore Parameters

  • store: The store to observe
  • observe: A function that transforms the store’s state into view state
  • removeDuplicates: An optional function to determine when state changes should trigger view updates
  • content: A view builder that receives the ViewStore and returns the content view

Migration Guide

Step 1: Add @ObservableState

Add the @ObservableState macro to your reducer’s state:

Step 2: Remove WithViewStore

Replace WithViewStore with direct store access:

Step 3: Update Send Calls

Change viewStore.send to store.send:

Benefits of Migration

  • Better Performance: Swift’s Observation framework is more efficient than ObservableObject
  • Less Boilerplate: No need to wrap views in WithViewStore
  • Simpler Code: Direct property access on stores
  • Type Safety: Better compile-time guarantees

See Also

  • @ObservableState: The modern way to make state observable
  • Store: The store type that powers TCA
  • Migration Guide