Slather logo

Coverage for "ClassWithContextFinder.swift" : 100.00%

(9 of 9 relevant lines covered)

RouteComposer/Classes/Finders/ClassWithContextFinder.swift

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