Destinationable
@MainActor
public protocol Destinationable<PresentationConfiguration> : AnyObject, 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 user interaction types for this Destination’s interface.
Declaration
Swift
associatedtype UserInteractionType : UserInteractionTypeable
-
An enum which defines all routable Destinations in the app.
Declaration
Swift
associatedtype DestinationType where Self.DestinationType == Self.PresentationConfiguration.DestinationType
-
An enum which defines types of Interactors. Each Destination may have its own Interactor types.
Declaration
Swift
associatedtype InteractorType : InteractorTypeable
-
An enum which defines types of tabs in a tab bar.
Declaration
Swift
associatedtype TabType where Self.TabType == Self.PresentationConfiguration.TabType
-
An enum which defines available Destination presentation types. Typically this is
DestinationPresentationType
.Declaration
Swift
associatedtype PresentationType : DestinationPresentationTypeable
-
An enum which defines the types of content that are able to be sent through Destinations.
Declaration
Swift
associatedtype ContentType where Self.ContentType == Self.PresentationConfiguration.ContentType
-
A model type which configures Destination presentations. Typically this is a
DestinationPresentation
.Declaration
Swift
associatedtype PresentationConfiguration : DestinationPresentationConfiguring
-
A type of
AppDestinationConfigurations
which handles Destination presentation configurations.Declaration
Swift
typealias DestinationConfigurations = AppDestinationConfigurations<UserInteractionType, PresentationConfiguration>
-
A type of
AppDestinationConfigurations
which handles system navigation events.Declaration
Swift
typealias NavigationConfigurations = AppDestinationConfigurations<SystemNavigationType, PresentationConfiguration>
-
The unique identifier for this Destination.
Declaration
Swift
@MainActor var id: UUID { get }
-
This enum value conforming to
RoutableDestinations
represents a specific Destination type.Declaration
Swift
@MainActor var type: DestinationType { get }
-
The identifier of this object’s parent Destination.
Declaration
Swift
@MainActor var parentDestinationID: UUID? { get set }
-
An
AppDestinationConfigurations
object representing configurations to handle user interactions on this Destination’s associated UI.Declaration
Swift
@MainActor var destinationConfigurations: DestinationConfigurations? { get set }
-
An
AppDestinationConfigurations
instance that holds configurations to handle system navigation events related to this Destination.Declaration
Swift
@MainActor var systemNavigationConfigurations: NavigationConfigurations? { get set }
-
A Boolean that denotes whether the UI is currently in a navigation transition.
Declaration
Swift
@MainActor var isSystemNavigating: Bool { get set }
-
A dictionary of interactors, with the associated keys being their interactor type.
Declaration
Swift
@MainActor var interactors: [InteractorType : any Interactable] { get set }
-
A dictionary of
InterfaceAction
objects, with the key being the associated user interaction type.Declaration
Swift
@MainActor var interfaceActions: [UserInteractionType : InterfaceAction<UserInteractionType, DestinationType, ContentType>] { get set }
-
A dictionary of system navigation interface actions which are run when certain system navigation events occur, with the key being the associated system navigation type.
Declaration
Swift
@MainActor var systemNavigationActions: [SystemNavigationType : InterfaceAction<SystemNavigationType, DestinationType, ContentType>] { get set }
-
A dictionary of assistants which help the Destination make requests of an interactor, with the key being the associated user interaction type.
Declaration
Swift
@MainActor var interactorAssistants: [UserInteractionType : any InteractorAssisting<Self>] { get set }
-
performInterfaceAction(interactionType:
Default implementationcontent: ) Performs the interface action associated with the specified user interaction type.
Default Implementation
Declaration
Swift
@MainActor func performInterfaceAction(interactionType: UserInteractionType, content: ContentType?) throws
Parameters
interactionType
The user interaction type whose action should be run.
content
Optional content to use with the interface action.
-
buildInterfaceActions(presentationClosure:
Default implementation) Builds the
InterfaceAction
objects to handle Destination presentations generated by this Destination. This should be called when configuring a Destination for presentation, typically from aFlowable
object.Default Implementation
Declaration
Swift
@MainActor func buildInterfaceActions(presentationClosure: @escaping (_ configuration: PresentationConfiguration) -> Void)
Parameters
presentationClosure
The presentation closure to be used in building the
InterfaceAction
objects. -
buildInterfaceAction(presentationClosure:
Default implementationconfiguration: interactionType: ) Builds an
InterfaceAction
object to handle the specified Destination presentation.Default Implementation
Declaration
Swift
@MainActor func buildInterfaceAction(presentationClosure: @escaping (DestinationConfigurations.PresentationConfiguration) -> Void, configuration: DestinationConfigurations.PresentationConfiguration, interactionType: UserInteractionType) -> InterfaceAction<UserInteractionType, DestinationType, ContentType>
Parameters
presentationClosure
A presentation closure to be used in building the
InterfaceAction
object.configuration
A model object used to configure the presentation.
interactionType
The user interaction type associated with this presentation.
Return Value
An
InterfaceAction
object for this presentation. -
buildInteractorActions(presentationClosure:
Default implementation) Builds the
InterfaceAction
objects to handle requests for this Destination’s interactors.Default Implementation
Declaration
Swift
@MainActor func buildInteractorActions(presentationClosure: @escaping (_ configuration: PresentationConfiguration) -> Void)
Parameters
presentationClosure
The presentation configuration object closure. Currently this is unused.
-
Updates the interface actions associated with this Destination.
Declaration
Swift
@MainActor func updateInterfaceActions(actions: [InterfaceAction<UserInteractionType, DestinationType, ContentType>])
Parameters
closures
An array of
InterfaceAction
objects 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
Flowable
object.Default Implementation
Declaration
Swift
@MainActor func buildSystemNavigationActions(presentationClosure: @escaping (PresentationConfiguration) -> Void)
Parameters
presentationClosure
A 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 (DestinationConfigurations.PresentationConfiguration) -> Void, configuration: DestinationConfigurations.PresentationConfiguration, navigationType: SystemNavigationType) -> InterfaceAction<SystemNavigationType, DestinationType, ContentType>
Parameters
presentationClosure
A closure which helps build the associated
InterfaceAction
.configuration
A model object which helps configure the system navigation action.
navigationType
The type of system navigation event associated with this action.
Return Value
An
InterfaceAction
object for this system event. -
Updates the system navigation closures associated with this Destination.
Declaration
Swift
@MainActor func updateSystemNavigationActions(actions: [InterfaceAction<SystemNavigationType, DestinationType, ContentType>])
Parameters
closures
An array of
InterfaceAction
objects 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) -> (PresentationConfiguration)?
Parameters
presentationID
The identifier of a presentation configuration object.
Return Value
The configuration object, or
nil
if 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) -> (PresentationConfiguration)?
Parameters
presentationID
The 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 type.
Default Implementation
Declaration
Swift
@MainActor func presentation(for interactionType: UserInteractionType) -> (PresentationConfiguration)?
Parameters
interactionType
The user interaction type.
Return Value
The configuration object, or
nil
if 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) -> (PresentationConfiguration)?
Parameters
navigationType
The system navigation type.
Return Value
The configuration object, or
nil
if 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: PresentationConfiguration)
Parameters
presentation
The 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: PresentationConfiguration)
Parameters
presentation
The presentation configuration object to replace an existing one.
-
Adds setup functionality for an interactor, which will add and register it with this Destination. An interactor handles specialized tasks and interactions with other APIs for the Destination.
Declaration
Swift
@MainActor func setupInteractor<Request, ResultData>(interactor: any Interactable<Request, ResultData>, for type: InteractorType) where Request : InteractorRequestConfiguring, ResultData : Hashable
Parameters
interactor
The interactor to add.
type
Specifies the type of interactor, which will be used to look up the interactor.
-
interactor(for:
Default implementation) Returns an interactor for the specified type.
Default Implementation
Declaration
Swift
@MainActor func interactor(for type: InteractorType) -> (any Interactable)?
Parameters
type
The type of 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 Interactable, type: InteractorType)
Parameters
interactor
The interactor to configure requests for.
type
The type of interactor.
-
addInterfaceAction(action:
Default implementation) Adds an interface action.
Default Implementation
Declaration
Swift
@MainActor func addInterfaceAction(action: InterfaceAction<UserInteractionType, DestinationType, ContentType>) throws
Parameters
closure
The 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
closure
The closure to add.
-
assignInteractorAssistant(assistant:
Default implementationfor: ) Assigns an interactor assistant to a specific type of user interaction.
Default Implementation
Declaration
Swift
@MainActor func assignInteractorAssistant(assistant: any InteractorAssisting<Self>, for interactionType: UserInteractionType)
Parameters
assistant
The interactor assistant to add.
interactionType
The type of user interaction which this assistant should handle requests for.
-
performRequest(interactor:
Default implementationrequest: completionClosure: ) Performs a request with the specified interactor.
Default Implementation
Declaration
Swift
@MainActor func performRequest<Request>(interactor: InteractorType, request: Request, completionClosure: DatasourceResponseClosure<[Request.ResultData]>?) where Request : InteractorRequestConfiguring
-
performRequest(interactor:
Default implementation, asynchronousrequest: ) Performs a request with the specified interactor asynchronously.
Default Implementation
Declaration
Swift
@MainActor func performRequest<Request>(interactor: InteractorType, request: Request) async -> Result<[Request.ResultData], Error> where Request : InteractorRequestConfiguring
Parameters
interactor
The type of interactor that should receive the request.
request
A model that defines the request.
Return Value
A
Result
containing 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
navigationType
The type of system navigation event to perform.
options
An optional options object for use with the closure.
-
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()
-
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()
-
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
closure
The throwable code to run.
catchClosure
An 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
error
The Error to log.
-
description
Extension methodA description of this object.
Declaration
Swift
@MainActor var description: String { get }