Destinationable
@MainActor
public protocol Destinationable<DestinationType, ContentType, TabType> : 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 : RoutableDestinations -
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 : 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.
Declaration
Swift
associatedtype ContentType : ContentTypeable -
A type of
AppDestinationConfigurationswhich handles Destination presentation configurations.Declaration
Swift
typealias DestinationConfigurations = AppDestinationConfigurations<UserInteractionType, 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<UserInteractionType, DestinationType, ContentType, TabType, InteractorType> { 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?) throwsParameters
interactionTypeThe user interaction type whose action should be run.
contentOptional content to use with the interface 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: interactionType: ) 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>, interactionType: UserInteractionType) -> InterfaceAction<UserInteractionType, DestinationType, ContentType>Parameters
presentationClosureA presentation closure to be used in building the
InterfaceActionobject.configurationA model object used to configure the presentation.
interactionTypeThe user interaction 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<UserInteractionType, 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 type.
Default Implementation
Declaration
Swift
@MainActor func presentation(for interactionType: UserInteractionType) -> (DestinationPresentation<DestinationType, ContentType, TabType>)?Parameters
interactionTypeThe user interaction 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
@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.
-
interactor(for:Default implementation) Returns an Interactor for the specified type.
Default Implementation
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.
-
addInterfaceAction(action:Default implementation) Adds an interface action.
Default Implementation
Declaration
Swift
@MainActor func addInterfaceAction(action: InterfaceAction<UserInteractionType, 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 type of user interaction.
Default Implementation
Declaration
Swift
@MainActor func assignInteractorAssistant(assistant: any InteractorAssisting<InteractorType, ContentType>, for interactionType: UserInteractionType)Parameters
assistantThe Interactor assistant to add.
interactionTypeThe type of user interaction which this assistant should handle requests for.
-
This method is called automatically when a Destination is being built and configured for the first time. Put any setup actions or datasource retrieval calls here.
Declaration
Swift
@MainActor func prepareForPresentation() -
performRequest(interactor:Default implementationrequest: ) Performs a request with the specified Interactor.
Default Implementation
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
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. -
handleInteractorResult(result:Default implementationfor: ) Handles the result of an Interactor request in a synchronous context.
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.
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.
-
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.
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: ) -
descriptionExtension methodA description of this object.
Declaration
Swift
@MainActor var description: String { get }
View on GitHub