1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// InlineContextTask.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 |
/// `InlineContextTask`
|
|
17 |
///
|
|
18 |
/// **NB:** It may be used for the purpose of configuration testing, but then replaced with a strongly typed
|
|
19 |
/// `ContextTask` instance.
|
|
20 |
public struct InlineContextTask<VC: UIViewController, C>: ContextTask {
|
|
21 |
|
|
22 |
// MARK: Properties
|
|
23 |
|
|
24 |
private let completion: (_: VC, _: C) throws -> Void
|
|
25 |
|
|
26 |
// MARK: Methods
|
|
27 |
|
|
28 |
/// Constructor
|
|
29 |
///
|
|
30 |
/// - Parameter completion: the block to be called when `InlineContextTask` will be applied to the `UIViewController`
|
|
31 |
/// instance.
|
|
32 |
public init(_ completion: @escaping (_: VC, _: C) throws -> Void) {
|
16x |
33 |
self.completion = completion
|
16x |
34 |
}
|
16x |
35 |
|
|
36 |
public func perform(on viewController: VC, with context: C) throws {
|
21x |
37 |
try completion(viewController, context)
|
21x |
38 |
}
|
21x |
39 |
|
|
40 |
}
|
|