SwitchAssembly
public final class SwitchAssembly<ViewController, Context> where ViewController : UIViewController
Builds a DestinationStep
which can contain the conditions to select the steps to be taken by a Router
.
Usage
let containerStep = SwitchAssembly<UINavigationController, ProductContext>()
.addCase { (context: ProductContext) in
// If this configuration is requested by a Universal Link (productURL != nil), skip this case otherwise.
guard context.productURL != nil else {
return nil
}
return ChainAssembly.from(NavigationControllerStep<UINavigationController, ProductContext>())
.using(GeneralAction.presentModally())
.from(GeneralStep.current())
.assemble()
}
// If UINavigationController is visible on the screen - use it
.addCase(from: ClassFinder<UINavigationController, ProductContext>(options: .currentVisibleOnly))
// Otherwise - create a UINavigationController and present modally
.assemble(default: ChainAssembly.from(NavigationControllerStep<UINavigationController, ProductContext>())
.using(GeneralAction.presentModally())
.from(GeneralStep.current())
.assemble())
-
Constructor
Declaration
Swift
public init()
-
Adds a block that allows a written decision case for the
Router
in the block. Returning nil from the block will mean that it has not succeeded.Declaration
Swift
public final func addCase(_ resolverBlock: @escaping (Context) -> DestinationStep<ViewController, Context>?) -> Self
Parameters
resolverBlock
case resolver block
-
Adds a case when a view controller exists in the stack in order to make a particular
DestinationStep
.Declaration
Swift
public final func addCase<F>(when finder: F, from step: DestinationStep<ViewController, Context>) -> Self where Context == F.Context, F : Finder
Parameters
finder
The
Finder
instance searches for aUIViewController
in the stackstep
The
DestinationStep
is to perform if theFinder
has been able to find a view controller in the stack. If not provided, aUIViewController
found by theFinder
will be considered as a view controller to start the navigation process from -
Adds a case when a certain condition is valid to use a particular
DestinationStep
.Declaration
Swift
public final func addCase(when condition: @autoclosure @escaping () -> Bool, from step: DestinationStep<ViewController, Context>) -> Self
Parameters
condition
A condition to use the provided step.
step
The
DestinationStep
is to perform. -
Adds a case when a certain condition is valid to use a particular
DestinationStep
.Declaration
Swift
public final func addCase(when conditionBlock: @escaping (Context) -> Bool, from step: DestinationStep<ViewController, Context>) -> Self
Parameters
conditionBlock
A condition to use the provided step.
step
The
DestinationStep
is to perform. -
Adds a case when a view controller exists - navigation will start from the resulting view controller.
Declaration
Swift
public final func addCase<F>(from finder: F) -> Self where ViewController == F.ViewController, Context == F.Context, F : Finder
-
Assembles all the cases into a
DestinationStep
implementationDeclaration
Swift
public final func assemble() -> DestinationStep<ViewController, Context>
Return Value
instance of a
DestinationStep
-
Assembles all the cases in a
DestinationStep
instance and adds the default implementation, providing the step it is to performDeclaration
Swift
public final func assemble(default resolverBlock: @escaping () -> DestinationStep<ViewController, Context>) -> DestinationStep<ViewController, Context>
Parameters
resolverBlock
default resolver block
Return Value
an instance of
DestinationStep
-
Assembles all the cases in a
DestinationStep
instance and adds the default implementation, providing the step it is to performDeclaration
Swift
public final func assemble(default step: DestinationStep<ViewController, Context>) -> DestinationStep<ViewController, Context>
Parameters
step
an instance of
DestinationStep
Return Value
a final instance of
DestinationStep
-
Adds a case when a view controller exists - navigation will start from the resulting view controller. This method allows to avoid view controller type check.
Declaration
Swift
final func addCase<F>(expecting finder: F) -> Self where Context == F.Context, F : Finder