WithViewStore
public struct WithViewStore<State, Action, Content> : View where Content : View
extension WithViewStore: DynamicViewContent where State: Collection, Content: DynamicViewContent
A structure that transforms a store into an observable view store in order to compute views from store state.
Due to a bug in SwiftUI, there are times that use of this view can interfere with some core views provided by SwiftUI. The known problematic views are:
- If a
GeometryReader
is used inside aWithViewStore
it will not receive state updates correctly. To work around you either need to reorder the views so thatGeometryReader
wraps theWithViewStore
, or, if that is not possible, then you must hold onto an explicit@ObservedObject var viewStore: ViewStore<State, Action>
in your view in lieu of using this helper (see here). - If you create a
Stepper
via theStepper.init(onIncrement:onDecrement:label:)
initializer inside aWithViewStore
it will behave erratically. To work around you should use the initializer that takes a binding (see here).
-
Initializes a structure that transforms a store into an observable view store in order to compute views from store state.
Declaration
Parameters
store
A store.
isDuplicate
A function to determine when two
State
values are equal. When values are equal, repeat view computations are removed,content
A function that can generate content from a view store.
-
Declaration
Swift
public var body: some View { get }
-
Prints debug information to the console whenever the view is computed.
Declaration
Swift
public func debug(_ prefix: String = "") -> WithViewStore<State, Action, Content>
Parameters
prefix
A string with which to prefix all debug messages.
Return Value
A structure that prints debug messages for all computations.
-
Initializes a structure that transforms a store into an observable view store in order to compute views from equatable store state.
Declaration
Parameters
store
A store of equatable state.
content
A function that can generate content from a view store.
-
Initializes a structure that transforms a store into an observable view store in order to compute views from equatable store state.
Declaration
Parameters
store
A store of equatable state.
content
A function that can generate content from a view store.