StateModeling
@MainActor
public protocol StateModeling<Destination> : AnyObject
This protocol represents a state model associated with a Destination.
-
Undocumented
Declaration
Swift
associatedtype Destination : Destinationable -
Undocumented
Declaration
Swift
typealias EventType = Destination.EventType -
Undocumented
Declaration
Swift
typealias InteractorType = Destination.InteractorType -
Undocumented
Declaration
Swift
typealias ContentType = Destination.ContentType -
The Destination associated with this state model.
This property should be assigned by the View or UIViewController in the state model’s initializer.
Declaration
Swift
@MainActor var destination: Destination? { get set } -
Performs an action tied to the Destination event of the specified type.
Important
This method should not be called directly. When a user interaction is made on a View or UIViewController, please call the
handleEvent(_:content:)method on the associated Destination instead.Declaration
Swift
@MainActor func handleEvent(_ type: EventType, content: ContentType?)Parameters
typeThe interaction event type to act upon.
contentAn optional content model to use when performing the action.
-
handleInteractorResult(result:Default implementationfor: ) Handles the result of an Interactor request in a synchronous context, forwarded from the Destination.
Default Implementation
Declaration
Swift
@MainActor func handleInteractorResult<Request>(result: Result<Request.ResultData, Error>, for request: Request) where Request : InteractorRequestConfiguringParameters
resultThe Result object containing data returned from the request.
requestThe original request used in this Interactor operation.
-
handleAsyncInteractorResult(result:Default implementation, asynchronousfor: ) Handles the result of an async Interactor request, forwarded from the Destination.
Default Implementation
Declaration
Swift
@MainActor func handleAsyncInteractorResult<Request>(result: Result<Request.ResultData, Error>, for request: Request) async where Request : InteractorRequestConfiguringParameters
resultThe Result object containing data returned from the request.
requestThe original request used in this Interactor operation.
-
prepareForPresentation()Default implementationImplement this method in your StateModeling classes to put any initial state setup actions or datasource retrieval calls here that should only be run when a state model is first created.
This method is called automatically when a Destination is presented by a Flow for the first time, but before its associated UI is built, and is forwarded to the state model. Unlike
prepareForAppearance(isVisible:), this method is only called once.Important
Do not call this method directly. This lifecycle method is called by the state model’s associated Destination.
Default Implementation
Declaration
Swift
@MainActor func prepareForPresentation() -
prepareForAppearance(isVisible:Default implementation) Implement this method in your StateModeling classes to place any setup tasks that need to be run each time the Destination’s UI element becomes active.
This method is called automatically when a Destination is about to be presented by a Flow, prior to the associated UI element appearing on-screen, and is forwarded to the state model. This method is preferred and is often more reliable than using native UI hooks like
View‘sonAppearmodifier in SwiftUI projects.Important
Do not call this method directly. This lifecycle method is called by the state model’s associated Destination.
Default Implementation
Declaration
Swift
@MainActor func prepareForAppearance(isVisible: Bool)Parameters
isVisibleRepresents whether this state model’s Destination will actually be visible on-screen when it is presented. If the Destination was presented within the middle of a Destination path presentation, it would be
false. This is useful for instance if you wish to avoid calling setup tasks unless it is the final Destination in a path presentation. -
prepareForDisappearance(wasVisible:Default implementation) This method is called automatically when a Destination is about to become inactive, and is forwarded to the state model. Implement this method in your StateModeling classes to place any teardown tasks that need to be run each time the Destination’s UI element is no longer visible or the active element.
This method is preferred and is often more reliable than using native UI hooks like
View‘sonDisappearmodifier in SwiftUI projects, and especially in cases where several UI elements may be added in quick succession in aNavigationStack.Important
Do not call this method directly. This lifecycle method is called by the state model’s associated Destination.
Default Implementation
Declaration
Swift
@MainActor func prepareForDisappearance(wasVisible: Bool)Parameters
wasVisibleRepresents whether the Destination which is disappearing was actually visible on-screen. If this Destination was presented within the middle of a Destination path presentation, it would be
false. -
configureInteractor(_:Default implementationtype: ) Configures the Interactor that is assigned to the Destination associated with this state model. You may use this method to make any initial requests to the Interactor to set up the interface’s initial state.
Important
Do not call this method directly. This lifecycle method is called automatically when an Interactor is assigned to the associated Destination.
Default Implementation
Declaration
Swift
@MainActor func configureInteractor(_ interactor: any AbstractInteractable, type: InteractorType)Parameters
interactorThe Interactor to configure requests for.
typeThe type of interactor.
-
cleanupResources()Default implementationWhen this method is called, the Destination is about to be removed from the Flow. Any resource references should be removed and in-progress interactor tasks should be stopped.
Default Implementation
Declaration
Swift
@MainActor func cleanupResources()
View on GitHub