1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// InstanceFinder.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 `Finder` that provides the `Router` a known instance of the `UIViewController`
|
|
17 |
public struct InstanceFinder<VC: UIViewController, C>: Finder {
|
|
18 |
|
|
19 |
// MARK: Associated types
|
|
20 |
|
|
21 |
public typealias ViewController = VC
|
|
22 |
|
|
23 |
public typealias Context = C
|
|
24 |
|
|
25 |
// MARK: Properties
|
|
26 |
|
|
27 |
/// The `UIViewController` instance that `Finder` will provide to the `Router`
|
|
28 |
public private(set) weak var instance: VC?
|
|
29 |
|
|
30 |
// MARK: Methods
|
|
31 |
|
|
32 |
/// Constructor
|
|
33 |
///
|
|
34 |
/// - Parameters:
|
|
35 |
/// - instance: The `UIViewController` instance that `Finder` should provide to the `Router`
|
|
36 |
public init(instance: VC) {
|
3x |
37 |
self.instance = instance
|
3x |
38 |
}
|
3x |
39 |
|
|
40 |
public func findViewController(with context: C) throws -> VC? {
|
4x |
41 |
instance
|
4x |
42 |
}
|
4x |
43 |
|
|
44 |
}
|
|