Slather logo

Coverage for "ClassFinder.swift" : 100.00%

(9 of 9 relevant lines covered)

RouteComposer/Classes/Finders/ClassFinder.swift

1
//
2
// RouteComposer
3
// ClassFinder.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
/// A default implementation of the view controllers finder that searches for a view controller by its name.
17
public struct ClassFinder<VC: UIViewController, C>: StackIteratingFinder {
18
19
    // MARK: Associated types
20
21
    public typealias ViewController = VC
22
23
    public typealias Context = C
24
25
    // MARK: Properties
26
27
    /// A `StackIterator` is to be used by `ClassFinder`
28
    public let iterator: StackIterator
29
30
    // MARK: Methods
31
32
    /// Constructor
33
    ///
34
    /// - Parameter iterator: A `StackIterator` is to be used by `ClassFinder`
35
    public init(iterator: StackIterator = RouteComposerDefaults.shared.stackIterator) {
94x
36
        self.iterator = iterator
94x
37
    }
94x
38
39
    public func isTarget(_ viewController: VC, with context: C) -> Bool {
84x
40
        true
84x
41
    }
84x
42
43
}
44
45
/// Extension to use `DefaultStackIterator` as default iterator.
46
public extension ClassFinder {
47
48
    /// Constructor
49
    ///
50
    /// Parameters
51
    ///   - options: A combination of the `SearchOptions`
52
    ///   - startingPoint: `DefaultStackIterator.StartingPoint` value
53
    ///   - windowProvider: `WindowProvider` instance.
54
    ///   - containerAdapterLocator: A `ContainerAdapterLocator` instance.
55
    init(options: SearchOptions,
56
         startingPoint: DefaultStackIterator.StartingPoint = .topmost,
57
         windowProvider: WindowProvider = RouteComposerDefaults.shared.windowProvider,
58
         containerAdapterLocator: ContainerAdapterLocator = RouteComposerDefaults.shared.containerAdapterLocator) {
78x
59
        self.iterator = DefaultStackIterator(options: options, startingPoint: startingPoint, windowProvider: windowProvider, containerAdapterLocator: containerAdapterLocator)
78x
60
    }
78x
61
62
}