RoutingInterceptor
@MainActor
public protocol RoutingInterceptor
RoutingInterceptor is called before the actual navigation process happens.
e.g. user should be logged in.
NB
Interceptor is an asynchronous action. For the Router to continue the navigation process, the completion block of the interceptor’s
execute method MUST be called.
Otherwise, the Router will stay in a limbo state waiting for the interceptor to finish its action.
-
Contexttype associated withRoutingInterceptorDeclaration
Swift
associatedtype Context
-
prepare(with:Default implementation) The
Routerwill call this method before the navigation process. IfRoutingInterceptoris not able to allow the navigation process to start it can stopRouterby throwing an exception.Throws
TheRoutingErrorif theRoutingInterceptorcannot prepare itself or if the navigation process cannot start with theContextinstance provided.Default Implementation
Default implementation does nothing.
Declaration
Swift
@MainActor mutating func prepare(with context: Context) throws -
Method that will be called by
Routerto start interceptor.NB
For the
Routerto continue the navigation process, thecompletionblock of interceptor MUST be called by the implementation of this method. OtherwiseRouterwill stay in limbo waiting forRoutingInterceptorto finish its action.Declaration
Swift
@MainActor func perform(with context: Context, completion: @escaping (RoutingResult) -> Void)
-
execute(with:Extension methodcompletion: ) Prepares the
RoutingInterceptorand executes itDeclaration
Swift
@MainActor func execute(with context: Context, completion: @escaping (RoutingResult) -> Void) throws -
commit(with:Extension methodcompletion: ) Prepares the
RoutingInterceptorand performs it. Does not throw an exception.Declaration
Swift
@MainActor func commit(with context: Context, completion: @escaping (RoutingResult) -> Void)
-
prepare()Extension methodThe
Routerwill call this method before the navigation process. IfRoutingInterceptoris not able to allow the navigation process to start it can stopRouterby throwing an exception.Throws
TheRoutingErrorif theRoutingInterceptorcannot prepare itself or if the navigation process cannot start with theContextinstance provided.Declaration
Swift
@MainActor mutating func prepare() throws -
perform(completion:Extension method) Method that will be called by
Routerto start interceptor.NB
For the
Routerto continue the navigation process, thecompletionblock of interceptor MUST be called by the implementation of this method. OtherwiseRouterwill stay in limbo waiting forRoutingInterceptorto finish its action.Declaration
Swift
@MainActor func perform(completion: @escaping (RoutingResult) -> Void)Parameters
completionCompletion block with a result.
-
execute(completion:Extension method) Prepares the
RoutingInterceptorand executes itDeclaration
Swift
@MainActor func execute(completion: @escaping (RoutingResult) -> Void) throws -
commit(completion:Extension method) Prepares the
RoutingInterceptorand performs it. Does not throw an exception.Declaration
Swift
@MainActor func commit(completion: @escaping (RoutingResult) -> Void)
-
prepare()Extension methodThe
Routerwill call this method before the navigation process. IfRoutingInterceptoris not able to allow the navigation process to start it can stopRouterby throwing an exception.Throws
TheRoutingErrorif theRoutingInterceptorcannot prepare itself or if the navigation process cannot start with theContextinstance provided.Declaration
Swift
@MainActor mutating func prepare() throws -
perform(completion:Extension method) Method that will be called by
Routerto start interceptor.NB
For the
Routerto continue the navigation process, thecompletionblock of interceptor MUST be called by the implementation of this method. OtherwiseRouterwill stay in limbo waiting forRoutingInterceptorto finish its action.Declaration
Swift
@MainActor func perform(completion: @escaping (RoutingResult) -> Void)Parameters
completionCompletion block with a result.
-
execute(completion:Extension method) Prepares the
RoutingInterceptorand executes itDeclaration
Swift
@MainActor func execute(completion: @escaping (RoutingResult) -> Void) throws -
commit(completion:Extension method) Prepares the
RoutingInterceptorand performs it. Does not throw an exception.Declaration
Swift
@MainActor func commit(completion: @escaping (RoutingResult) -> Void)