1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// PostRoutingTaskBox.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 |
struct PostRoutingTaskBox<PT: PostRoutingTask>: AnyPostRoutingTask, MainThreadChecking, CustomStringConvertible {
|
|
17 |
|
|
18 |
let postRoutingTask: PT
|
|
19 |
|
|
20 |
init(_ postRoutingTask: PT) {
|
18x |
21 |
self.postRoutingTask = postRoutingTask
|
18x |
22 |
}
|
18x |
23 |
|
|
24 |
func perform(on viewController: UIViewController,
|
|
25 |
with context: AnyContext,
|
|
26 |
routingStack: [UIViewController]) throws {
|
26x |
27 |
guard let typedViewController = viewController as? PT.ViewController else {
|
26x |
28 |
throw RoutingError.typeMismatch(type: type(of: viewController),
|
1x |
29 |
expectedType: PT.ViewController.self,
|
1x |
30 |
.init("\(String(describing: postRoutingTask.self)) does not support \(String(describing: viewController.self))."))
|
1x |
31 |
}
|
25x |
32 |
let typedDestination: PT.Context = try context.value()
|
25x |
33 |
assertIfNotMainThread()
|
25x |
34 |
postRoutingTask.perform(on: typedViewController, with: typedDestination, routingStack: routingStack)
|
25x |
35 |
}
|
25x |
36 |
|
|
37 |
var description: String {
|
2x |
38 |
String(describing: postRoutingTask)
|
2x |
39 |
}
|
2x |
40 |
|
|
41 |
}
|
|