Destinationable
@MainActor
public protocol Destinationable<DestinationType, ContentType, TabType> : AssistantAssigning, InteractorResultHandling, Identifiable
This protocol represents a Destination in the Destinations ecosystem.
A Destination represents a unique area in an app which can be navigated to by the user. In SwiftUI this is typically a fullscreen View object, and in UIKit it’s a UIViewController class or subclass, but it can also be a group of Destinations like a TabBar or a carousel. Destinations hold references to the UI element they’re associated with, but they don’t handle the particulars of laying out elements on the screen. Instead, the role of Destination objects in the ecosystem is to send and receive messages and datasource requests on behalf of their UI, such as passing on a message to trigger an action when a user taps a button.
In most cases you should be able to use the provided ViewDestination or ControllerDestination classes for SwiftUI or UIKit apps respectively. They are customized to a particular Destination through generic arguments. To handle presentation requests that require specialized configuration or need to handle content models, you can create custom assistants which conform to the InterfaceActionConfiguring protocol. To handle requests to an interactor, you can create assistants which conform to the InteractorAssisting protocol. There are more specific classes to support interfaces like TabBars, but you can also use your own Destination classes by conforming to ViewDestinationable or ControllerDestinationable if you should need custom functionality or just want to avoid using generics.
There is a two-way connection between a Destination and its interface which is handled by a DestinationStateable-conforming object. Destinations comes with a DestinationInterfaceState object which can be used for this purpose, though you can create your own class if you’d like to store other state in it. When a Destination is removed from the ecosystem, cleanup is done internally to ensure no retain cycles occur.
-
An enum which defines event types for this Destination’s interface.
Declaration
Swift
associatedtype EventType : EventTypeable -
An enum which defines all routable Destinations in the app.
Declaration
Swift
associatedtype DestinationType : RoutableDestinations -
An enum which defines types of tabs in a tab bar.
Declaration
Swift
associatedtype TabType : TabTypeable -
An enum which defines available Destination presentation types.
Declaration
Swift
typealias PresentationType = DestinationPresentationType<DestinationType, ContentType, TabType> -
An enum which defines the types of content that are able to be sent through Destinations. A type of
AppDestinationConfigurationswhich handles Destination presentation configurations.Declaration
Swift
typealias DestinationConfigurations = AppDestinationConfigurations<EventType, DestinationType, ContentType, TabType> -
A type of
AppDestinationConfigurationswhich handles system navigation events.Declaration
Swift
typealias NavigationConfigurations = AppDestinationConfigurations<SystemNavigationType, DestinationType, ContentType, TabType> -
The unique identifier for this Destination.
Declaration
Swift
@MainActor var id: UUID { get } -
This enum value conforming to
RoutableDestinationsrepresents a specific Destination type.Declaration
Swift
@MainActor var type: DestinationType { get } -
State object for handling functionality for the Destinations ecosystem.
Declaration
Swift
@MainActor var internalState: DestinationInternalState<EventType, DestinationType, ContentType, TabType, InteractorType> { get set } -
stateModelDefault implementationA state model that handles business logic and view state for this Destination.
Default Implementation
Declaration
Swift
@MainActor var stateModel: (any StateModeling<Self>)? { get set } -
performAction(for:Default implementationcontent: ) Performs the action associated with the specified event type. This action could be a Destination presentation or a request to an Interactor. The response is returned with a delegate pattern in
handleInteractorResult(result:for:).This is the method to use for Destination presentations.
Default Implementation
Declaration
Swift
@MainActor func performAction(for eventType: EventType, content: ContentType?) throwsParameters
eventTypeThe event type whose action should be run.
contentOptional content to use with the action.
-
performAction(for:Default implementation, asynchronouscontent: ) Asynchronously performs the Interactor action associated with the specified event type and returns its Result.
If a result transformer is registered for this event type, it’s used to convert the Interactor’s
Request.ResultDataintoContentType. Otherwise a direct cast is attempted, which succeeds when the two types are the same.Important
Use this method for event types bound to an Interactor. If the event type is bound to a presentation, this method performs the presentation and then returns
presentationResultNotSupported(message:), because presentations have no result value to return. That error doesn’t mean the presentation failed. The method also doesn’t wait for the presented interface to appear on screen. Use the throwingperformAction(for:content:)for presentation events. This behavior for presentations may change in a future version.Default Implementation
Declaration
Swift
@MainActor func performAction(for eventType: EventType, content: ContentType?) async -> Result<ContentType, Error>Parameters
eventTypeThe event type whose action should be run.
contentOptional content to use with the action.
-
performActions(for:Default implementation, asynchronouscontent: ) Performs the action sequence associated with the specified event type, running each of its Interactor actions in order and passing the result of each action to the next one through its output conduit. The sequence will run until either all actions have completed, an action returns an error, or the sequence is cancelled.
The event type should be associated with a configuration conforming to
ActionCollectionConfiguring, such as anActionSequenceConfigurationor anActionGroupConfiguration. For an event associated with a singleInteractorConfiguration, useperformAction(for:content:)instead; this method returnsincompatibleType(message:)for it.Default Implementation
Declaration
Swift
@MainActor func performActions(for eventType: EventType, content: ContentType?) async -> Result<ActionCollectionResults<ContentType>, any Error>Parameters
eventTypeThe event type corresponding to the action sequence to be run.
contentOptional content to pass to the sequence. Each step in the sequence determines how this content should be used, but generally it should be passed in with the first action’s Interactor request.
Return Value
A
Resultcontaining anActionSequenceResultsobject which holds the results of each completed action, or anErrorif the sequence could not be built or one of its actions failed. If the sequence was cancelled, the failure contains ancancelled(partialResults:)error holding the results of any actions which completed before cancellation occurred. -
performActions(configuration:Default implementation, asynchronouscontent: ) Performs a custom action sequence using the provided configuration, running each of its Interactor actions in order and passing the result of each action to the next one through its output conduit. The sequence will run until either all actions have completed, an action returns an error, or the sequence is cancelled.
Use this overload when you want to supply a sequence configuration directly rather than relying on one pre-registered with the event type.
Important
Use of this method (and the lack of eventType to reference in
cancelActionSequence(for:)-1z0z5means that the caller responsible for task cancellation by saving the Task wrapping this method to a property and callingTask.cancel()on it.Default Implementation
Declaration
Swift
@MainActor func performActions(configuration: any ActionCollectionConfiguring<InteractorType, ContentType>, content: ContentType?) async -> Result<ActionCollectionResults<ContentType>, any Error>Parameters
configurationAn object conforming to
ActionCollectionConfiguringwhich defines the sequence of Interactor actions to run.contentOptional content to pass to the sequence. Each step in the sequence determines how this content should be used, but generally it should be passed in with the first action’s Interactor request.
Return Value
A
Resultcontaining anActionSequenceResultsobject which holds the results of each completed action, or anErrorif the sequence could not be built or one of its actions failed. If the sequence was cancelled, the failure contains ancancelled(partialResults:)error holding the results of any actions which completed before cancellation occurred. -
cancelAllActionSequences()Default implementationCancels all in-progress action sequences on this Destination. This is called automatically by a Flow when this Destination is removed from it.
Default Implementation
Declaration
Swift
@MainActor func cancelAllActionSequences() -
performInterfaceAction(eventType:Default implementationcontent: ) Performs the action associated with the specified event type.
Default Implementation
Declaration
Swift
@available(*, deprecated, renamed: "performAction(for:content:﹚", message: "This method is deprecated and will be removed in a future version. Please migrate your code to use the `performAction(for:content:﹚` method instead.") @MainActor func performInterfaceAction(eventType: EventType, content: ContentType?) throwsParameters
eventTypeThe event type whose action should be run.
contentOptional content to use with the action.
-
buildInterfaceActions(presentationClosure:Default implementation) Builds the
InterfaceActionobjects to handle Destination presentations generated by this Destination. This should be called when configuring a Destination for presentation, typically from aFlowableobject.Default Implementation
Declaration
Swift
@MainActor func buildInterfaceActions(presentationClosure: @escaping (_ configuration: DestinationPresentation<DestinationType, ContentType, TabType>) -> Void)Parameters
presentationClosureThe presentation closure to be used in building the
InterfaceActionobjects. -
buildInterfaceAction(presentationClosure:Default implementationconfiguration: eventType: ) Builds an
InterfaceActionobject to handle the specified Destination presentation.Default Implementation
Declaration
Swift
@MainActor func buildInterfaceAction(presentationClosure: @escaping (DestinationPresentation<DestinationType, ContentType, TabType>) -> Void, configuration: DestinationPresentation<DestinationType, ContentType, TabType>, eventType: EventType) -> InterfaceAction<EventType, DestinationType, ContentType>Parameters
presentationClosureA presentation closure to be used in building the
InterfaceActionobject.configurationA model object used to configure the presentation.
eventTypeThe event type associated with this presentation.
Return Value
An
InterfaceActionobject for this presentation. -
buildInteractorActions(presentationClosure:Default implementation) Builds the
InterfaceActionobjects to handle requests for this Destination’s interactors.Default Implementation
Declaration
Swift
@MainActor func buildInteractorActions(presentationClosure: @escaping (_ configuration: DestinationPresentation<DestinationType, ContentType, TabType>) -> Void)Parameters
presentationClosureThe presentation configuration object closure. Currently this is unused.
-
Updates the interface actions associated with this Destination.
Declaration
Swift
@MainActor func updateInterfaceActions(actions: [InterfaceAction<EventType, DestinationType, ContentType>])Parameters
closuresAn array of
InterfaceActionobjects containing user interaction closures to be run. -
buildSystemNavigationActions(presentationClosure:Default implementation) Builds the system navigation actions. This should be called when configuring a Destination for presentation, typically from a
Flowableobject.Default Implementation
Declaration
Swift
@MainActor func buildSystemNavigationActions(presentationClosure: @escaping (DestinationPresentation<DestinationType, ContentType, TabType>) -> Void)Parameters
presentationClosureA closure passing in a presentation configuration object to be used in building the system navigation closures.
-
buildSystemNavigationAction(presentationClosure:Default implementationconfiguration: navigationType: ) Builds a system navigation action.
Default Implementation
Declaration
Swift
@MainActor func buildSystemNavigationAction(presentationClosure: @escaping (DestinationPresentation<DestinationType, ContentType, TabType>) -> Void, configuration: DestinationPresentation<DestinationType, ContentType, TabType>, navigationType: SystemNavigationType) -> InterfaceAction<SystemNavigationType, DestinationType, ContentType>Parameters
presentationClosureA closure which helps build the associated
InterfaceAction.configurationA model object which helps configure the system navigation action.
navigationTypeThe type of system navigation event associated with this action.
Return Value
An
InterfaceActionobject for this system event. -
Updates the system navigation closures associated with this Destination.
Declaration
Swift
@MainActor func updateSystemNavigationActions(actions: [InterfaceAction<SystemNavigationType, DestinationType, ContentType>])Parameters
closuresAn array of
InterfaceActionobjects containing system navigation closures to be run. -
presentation(presentationID:Default implementation) Returns a presentation configuration object based on its identifier.
Default Implementation
Declaration
Swift
@MainActor func presentation(presentationID: UUID) -> (DestinationPresentation<DestinationType, ContentType, TabType>)?Parameters
presentationIDThe identifier of a presentation configuration object.
Return Value
The configuration object, or
nilif the specified object was not found. -
systemNavigationPresentation(presentationID:Default implementation) Returns a system navigation configuration object based on its identifier.
Default Implementation
Declaration
Swift
@MainActor func systemNavigationPresentation(presentationID: UUID) -> (DestinationPresentation<DestinationType, ContentType, TabType>)?Parameters
presentationIDThe identifier of a presentation configuration object.
Return Value
The system navigation configuration object, if one was found.
-
presentation(for:Default implementation) Returns a presentation configuration object based on its associated user interaction event type.
Default Implementation
Declaration
Swift
@MainActor func presentation(for eventType: EventType) -> (DestinationPresentation<DestinationType, ContentType, TabType>)?Parameters
eventTypeThe user interaction event type.
Return Value
The configuration object, or
nilif the specified object was not found. -
systemNavigationPresentation(for:Default implementation) Returns a system navigation configuration object based on its associated type.
Default Implementation
Declaration
Swift
@MainActor func systemNavigationPresentation(for navigationType: SystemNavigationType) -> (DestinationPresentation<DestinationType, ContentType, TabType>)?Parameters
navigationTypeThe system navigation type.
Return Value
The configuration object, or
nilif the specified object was not found. -
updatePresentation(presentation:Default implementation) Updates an existing presentation with a new configuration object. If no presentation is found which matches this object’s identifier, nothing is updated.
Default Implementation
Declaration
Swift
@MainActor func updatePresentation(presentation: DestinationPresentation<DestinationType, ContentType, TabType>)Parameters
presentationThe presentation configuration object to replace an existing one.
-
updateSystemNavigationPresentation(presentation:Default implementation) Updates an existing system navigation presentation with a new configuration object. If no system navigation object is found which matches this object’s identifier, nothing is updated.
Default Implementation
Declaration
Swift
@MainActor func updateSystemNavigationPresentation(presentation: DestinationPresentation<DestinationType, ContentType, TabType>)Parameters
presentationThe presentation configuration object to replace an existing one.
-
Assigns an Interactor to this Destination. An Interactor handles specialized tasks and interactions with other APIs for the Destination.
Declaration
Swift
@available(*, deprecated, renamed: "assignInteractor(_:to:﹚", message: "This method is deprecated and will be removed in a future version. Please migrate your code to use the `assignInteractor(_:to:﹚` method instead.") @MainActor func assignInteractor<Request>(interactor: any AbstractInteractable<Request>, for type: InteractorType) where Request : InteractorRequestConfiguringParameters
interactorThe Interactor to add.
typeSpecifies the enum type of this Interactor. This type can be used to look up the Interactor.
-
Assigns an Interactor to this Destination. An Interactor handles specialized tasks and interactions with other APIs for the Destination.
Declaration
Swift
@MainActor func assignInteractor<Request>(_ interactor: any AbstractInteractable<Request>, to type: InteractorType) where Request : InteractorRequestConfiguringParameters
interactorThe Interactor to add.
typeSpecifies the enum type of this Interactor. This type can be used to look up the Interactor.
-
interactor(for:Default implementation) Returns an Interactor for the specified type.
Default Implementation
Undocumented
Declaration
Swift
@MainActor func interactor(for type: InteractorType) -> (any AbstractInteractable)?Parameters
typeThe enum type of an Interactor.
Return Value
An Interactor, if one was found.
-
configureInteractor(_:Default implementationtype: ) Configures the Interactor that is assigned to this Destination. You may use this method to make any initial requests to the Interactor to set up the interface’s initial state. This method is called automatically when an Interactor is assigned to it.
Default Implementation
Declaration
Swift
@MainActor func configureInteractor(_ interactor: any AbstractInteractable, type: InteractorType)Parameters
interactorThe Interactor to configure requests for.
typeThe type of interactor.
-
configureInteractors()Default implementationConfigures all Interactors that are assigned to this Destination. This method is called internally by this Destination’s Provider.
Default Implementation
Declaration
Swift
@MainActor func configureInteractors() -
addInterfaceAction(action:Default implementation) Adds an interface action.
Default Implementation
Declaration
Swift
@MainActor func addInterfaceAction(action: InterfaceAction<EventType, DestinationType, ContentType>) throwsParameters
closureThe closure to add.
-
addSystemNavigationAction(action:Default implementation) Adds a system navigation closure.
Default Implementation
Declaration
Swift
@MainActor func addSystemNavigationAction(action: InterfaceAction<SystemNavigationType, DestinationType, ContentType>)Parameters
closureThe closure to add.
-
assignInteractorAssistant(assistant:Default implementationfor: ) Assigns an Interactor assistant to a specific event type.
Default Implementation
Declaration
Swift
@MainActor func assignInteractorAssistant(assistant: any InteractorAssisting<InteractorType, ContentType>, for eventType: EventType)Parameters
assistantThe Interactor assistant to add.
eventTypeThe type of event which this assistant should handle requests for.
-
prepareForPresentation()Default implementationThis method is called automatically when a Destination is presented by a Flow for the first time, but before its associated UI is built. Implement this method in your Destination classes to put any initial state setup actions or datasource retrieval calls here that should only be run when a Destination is first created.
Unlike
prepareForAppearance(isVisible:), this method is only called once on a Destination.Default Implementation
Declaration
Swift
@MainActor func prepareForPresentation() -
prepareForAppearance(isVisible:Default implementation) 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. Implement this method in your Destination classes to place any setup tasks that need to be run each time the Destination’s UI element becomes active.
This method is preferred and is often more reliable than using native UI hooks like
View‘sonAppearmodifier in SwiftUI projects.Default Implementation
Declaration
Swift
@MainActor func prepareForAppearance(isVisible: Bool)Parameters
isVisibleRepresents whether this Destination will actually be visible on-screen when it is presented. If this 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. Implement this method in your Destination 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.Default Implementation
Declaration
Swift
@MainActor func prepareForDisappearance(wasVisible: Bool)Parameters
wasVisibleRepresents whether this 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. -
performRequest(interactor:Default implementationrequest: ) Performs a request with the specified Interactor.
Default Implementation
Undocumented
Declaration
Swift
@MainActor func performRequest<Request>(interactor: InteractorType, request: Request) where Request : InteractorRequestConfiguring -
performRequest(interactor:Default implementation, asynchronousrequest: ) Performs a request with the specified Interactor asynchronously.
Default Implementation
Undocumented
Declaration
Swift
@MainActor func performRequest<Request>(interactor: InteractorType, request: Request) async -> Result<Request.ResultData, Error> where Request : InteractorRequestConfiguringParameters
interactorThe type of Interactor that should receive the request.
requestA model that defines the request.
Return Value
A
Resultcontaining an array of items. -
performSystemNavigationAction(navigationType:Default implementationoptions: ) Performs a system navigation action, executing the closure associated with the provided system navigation type.
Default Implementation
Declaration
Swift
@MainActor func performSystemNavigationAction<T>(navigationType: SystemNavigationType, options: T?)Parameters
navigationTypeThe type of system navigation event to perform.
optionsAn optional options object for use with the closure.
-
setParentID(id:Default implementation) Sets the parent Destination identifier of this child.
Default Implementation
Declaration
Swift
@MainActor func setParentID(id: UUID)Parameters
idThe identifier of the parent Destination.
-
updateIsSystemNavigating(isNavigating:Default implementation) Updates the
isSystemNavigatingproperty of the internal state.Default Implementation
Declaration
Swift
@MainActor func updateIsSystemNavigating(isNavigating: Bool)Parameters
isNavigatingThe new value.
-
isSystemNavigating()Default implementationReturns the current value of the
isSystemNavigatingproperty of the internal state.Default Implementation
Declaration
Swift
@MainActor func isSystemNavigating() -> BoolReturn Value
The current value.
-
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.
Note
In-progress action sequences do not need to be handled here; the Flow cancels them automatically when removing the Destination.
Default Implementation
Declaration
Swift
@MainActor func cleanupResources() -
Removes the associated interface from this Destination. This method is called automatically when a Destination is removed in order to avoid a retain cycle.
Declaration
Swift
@MainActor func removeAssociatedInterface() -
parentDestinationID()Default implementationReturns the identifier of this Destination’s parent, if one exists.
Default Implementation
Declaration
Swift
@MainActor func parentDestinationID() -> UUID?Return Value
The parent identifier.
-
handleThrowable(closure:Default implementationcatchClosure: ) Provides a way to catch and log Destinations errors from throwable code.
Default Implementation
Declaration
Swift
@MainActor func handleThrowable(closure: @escaping () throws -> Void, catchClosure: (() -> Void)?)Parameters
closureThe throwable code to run.
catchClosureAn optional closure to run if the try is caught.
-
logError(error:Default implementation) Logs an error to the Destinations logger. It handles DestinationError messages appropriately.
Default Implementation
Declaration
Swift
@MainActor func logError(error: Error)Parameters
errorThe Error to log.
-
performRequest(interactor:Extension methodrequest: ) -
handleInteractorResult(result:Extension methodfor: ) Declaration
Swift
@MainActor func handleInteractorResult<Request>(result: Result<Request.ResultData, Error>, for request: Request) where Request : InteractorRequestConfiguring -
handleAsyncInteractorResult(result:Extension method, asynchronousfor: ) Declaration
Swift
@MainActor func handleAsyncInteractorResult<Request>(result: Result<Request.ResultData, Error>, for request: Request) async where Request : InteractorRequestConfiguring -
descriptionExtension methodA description of this object.
Declaration
Swift
@MainActor var description: String { get }
-
tryAssignInteractorAssistant(_:Extension methodfor: ) Declaration
Swift
@discardableResult @MainActor func tryAssignInteractorAssistant(_ assistant: any Sendable, for eventType: any Hashable) -> Bool
View on GitHub