| 1 |
//
|
|
| 2 |
// RouteComposer
|
|
| 3 |
// SimpleContainerFactory.swift
|
|
| 4 |
// https://github.com/ekazaev/route-composer
|
|
| 5 |
//
|
|
| 6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
| 7 |
// Distributed under the MIT license.
|
|
| 8 |
//
|
|
| 9 |
// Become a sponsor:
|
|
| 10 |
// https://github.com/sponsors/ekazaev
|
|
| 11 |
//
|
|
| 12 |
|
|
| 13 |
import Foundation
|
|
| 14 |
import UIKit
|
|
| 15 |
|
|
| 16 |
/// A helper protocol to the `ContainerFactory` protocol. If a container does not need to deal with the children view
|
|
| 17 |
/// controller creation, `SimpleContainerFactory` will handle integration of the children view controllers.
|
|
| 18 |
public protocol SimpleContainerFactory: ContainerFactory {
|
|
| 19 |
|
|
| 20 |
// MARK: Associated types
|
|
| 21 |
|
|
| 22 |
/// Type of `UIViewController` that `SimpleContainerFactory` can build
|
|
| 23 |
associatedtype ViewController
|
|
| 24 |
|
|
| 25 |
/// `Context` to be passed into `UIViewController`
|
|
| 26 |
associatedtype Context
|
|
| 27 |
|
|
| 28 |
// MARK: Methods to implement
|
|
| 29 |
|
|
| 30 |
/// Builds a `UIViewController` that will be integrated into the stack
|
|
| 31 |
///
|
|
| 32 |
/// Parameters:
|
|
| 33 |
/// - context: A `Context` instance provided to the `Router`.
|
|
| 34 |
/// - viewControllers: `UIViewController` instances to be integrated into the container as children view controllers
|
|
| 35 |
/// - Returns: The built `UIViewController` container instance.
|
|
| 36 |
/// - Throws: The `RoutingError` if the build does not succeed.
|
|
| 37 |
func build(with context: Context, integrating viewControllers: [UIViewController]) throws -> ViewController
|
|
| 38 |
|
|
| 39 |
}
|
|
| 40 |
|
|
| 41 |
public extension SimpleContainerFactory {
|
|
| 42 |
|
|
| 43 |
/// Default implementation of the `ContainerFactory`'s `build` method
|
|
| 44 |
func build(with context: Context, integrating coordinator: ChildCoordinator) throws -> ViewController {
|
1x |
| 45 |
let viewControllers = try coordinator.build()
|
1x |
| 46 |
return try build(with: context, integrating: viewControllers)
|
1x |
| 47 |
}
|
1x |
| 48 |
|
|
| 49 |
}
|
|