Slather logo

Coverage for "Action.swift" : 100.00%

(3 of 3 relevant lines covered)

RouteComposer/Classes/Action.swift

1
//
2
// RouteComposer
3
// Action.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 UIKit
14
15
/// Represents an action that has to be applied to the `UIViewController` after it has
16
/// been built (eg: push to navigation stack, present modally, push to tab, etc)
17
public protocol Action: AbstractAction {}
18
19
/// Represents an action to be used by a `ContainerFactory` to build it's children view controller stack
20
public protocol ContainerAction: AbstractAction where ViewController: ContainerViewController {
21
22
    // MARK: Methods to implement
23
24
    /// If current `UIViewController` has to be pushed/added/etc to the existing stack of the view controllers,
25
    /// this method should be called instead.
26
    ///
27
    /// - Parameters:
28
    ///   - viewController: The `UIViewController` to be embedded.
29
    ///   - childViewControllers: The stack of the `UIViewController`s in the current container.
30
    func perform(embedding viewController: UIViewController, in childViewControllers: inout [UIViewController]) throws
31
32
}
33
34
// MARK: Default implementation
35
36
public extension ContainerAction {
37
38
    func perform(embedding viewController: UIViewController, in childViewControllers: inout [UIViewController]) {
36x
39
        childViewControllers.append(viewController)
36x
40
    }
36x
41
42
}