Slather logo

Coverage for "PostRoutingTask.swift" : 100.00%

(6 of 6 relevant lines covered)

RouteComposer/Classes/PostRoutingTask.swift

1
//
2
// RouteComposer
3
// PostRoutingTask.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
/// The task to be executed after navigation process happened.
17
public protocol PostRoutingTask {
18
19
    // MARK: Associated types
20
21
    /// `UIViewController` type associated with this `PostRoutingTask`
22
    associatedtype ViewController: UIViewController
23
24
    /// `Context` type associated with this `PostRoutingTask`
25
    associatedtype Context
26
27
    // MARK: Methods to implement
28
29
    /// Method to be executed by the `Router` after all the view controllers have been built into the stack.
30
    ///
31
    /// - Parameters:
32
    ///   - viewController: The `UIViewController` instance that this post-task has been attached to
33
    ///   - context: The `Context` instance provided to the `Router`
34
    ///   - routingStack: An array of all the view controllers that been built by the `Router` to
35
    ///     reach the final destination
36
    func perform(on viewController: ViewController, with context: Context, routingStack: [UIViewController])
37
38
}
39
40
// MARK: Helper methods where the Context is Any?
41
42
public extension PostRoutingTask where Context == Any? {
43
44
    /// Method to be executed by the `Router` after all the view controllers have been built into the stack.
45
    ///
46
    /// - Parameters:
47
    ///   - viewController: The `UIViewController` instance that this post-task has been attached to
48
    ///   - routingStack: An array of all the view controllers that been built by the `Router` to
49
    ///     reach the final destination
50
    func perform(on viewController: ViewController, routingStack: [UIViewController]) {
1x
51
        perform(on: viewController, with: nil, routingStack: routingStack)
1x
52
    }
1x
53
54
}
55
56
// MARK: Helper methods where the Context is Void
57
58
public extension PostRoutingTask where Context == Void {
59
60
    /// Method to be executed by the `Router` after all the view controllers have been built into the stack.
61
    ///
62
    /// - Parameters:
63
    ///   - viewController: The `UIViewController` instance that this post-task has been attached to
64
    ///   - routingStack: An array of all the view controllers that been built by the `Router` to
65
    ///     reach the final destination
66
    func perform(on viewController: ViewController, routingStack: [UIViewController]) {
1x
67
        perform(on: viewController, with: (), routingStack: routingStack)
1x
68
    }
1x
69
70
}