1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
import Foundation
|
|
14 |
import UIKit
|
|
15 |
|
|
16 |
|
|
17 |
public struct LastStepInChainAssembly<ViewController: UIViewController, Context> {
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
let previousSteps: [RoutingStep]
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
init(previousSteps: [RoutingStep]) {
|
202x |
26 |
self.previousSteps = previousSteps
|
202x |
27 |
}
|
202x |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
public func assemble() -> DestinationStep<ViewController, Context> {
|
202x |
33 |
DestinationStep(chain(previousSteps))
|
202x |
34 |
}
|
202x |
35 |
|
|
36 |
private func chain(_ steps: [RoutingStep]) -> RoutingStep {
|
202x |
37 |
guard let lastStep = steps.last else {
|
202x |
38 |
preconditionFailure("No steps provided to chain.")
|
! |
39 |
}
|
202x |
40 |
|
202x |
41 |
let firstStep = steps.dropLast().reversed().reduce(lastStep) { result, currentStep in
|
248x |
42 |
guard var step = currentStep as? BaseStep else {
|
248x |
43 |
assertionFailure("\(currentStep) can not be chained to non chainable step \(result)")
|
! |
44 |
return currentStep
|
! |
45 |
}
|
248x |
46 |
step.from(result)
|
248x |
47 |
return step
|
248x |
48 |
}
|
248x |
49 |
|
202x |
50 |
return firstStep
|
202x |
51 |
}
|
202x |
52 |
|
|
53 |
}
|
|