View

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension View
  • Performs an action asynchronously on the main thread when a view appears.

    SwiftUI doesn’t update a view if changes are performed in the onAppear method. This includes changes to the application state from dispatched actions. This method allows actions to be dispatched when the view appears.

    Declaration

    Swift

    @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
    public func onAppearAsync(perform: @escaping () -> Void) -> some View

    Parameters

    perform

    The action to run asynchronously

    Return Value

    The modified view.

  • Performs an action asynchronously on the main thread when a view appears.

    Declaration

    Swift

    @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
    public func onDisappearAsync(perform: @escaping () -> Void) -> some View

    Parameters

    perform

    The action to run asynchronously

    Return Value

    The modified view.

  • Fires when a child view dispatches an action.

    Declaration

    Swift

    @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
    public func onAction(perform: @escaping ActionModifier) -> some View

    Parameters

    perform

    Calls the closure when an action is dispatched. An optional new action can be returned to change the action.

    Return Value

    The modified view.

  • Connect the application state to the UI.

    The returned mapped state is provided to the environment and accessible through the MappedState property wrapper.

    Declaration

    Swift

    @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
    public func connect<Superstate, State>(
      updateWhen filter: @escaping (Action) -> Bool = { $0 is NoUpdateAction },
      mapState: @escaping (Superstate) -> State?
    ) -> some View

    Return Value

    The modified view.

  • Injects a store into the environment.

    The store can then be used by the @EnvironmentObject property wrapper. This method also enables the use of View.mapState(updateOn:_:) to map substates to a view.

    struct RootView: View {
      // Passed in from the AppDelegate or SceneDelegate class.
      var store: Store<AppState>
    
    
      var body: some View {
        RootAppNavigation()
          .provideStore(store)
      }
    
    }
    

    Declaration

    Swift

    @available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
    public func provideStore<State>(_ store: Store<State>) -> some View where State : Decodable, State : Encodable

    Parameters

    store

    The store object to inject.

    Return Value

    The modified view.