Slather logo

Coverage for "FinderBox.swift" : 100.00%

(13 of 13 relevant lines covered)

RouteComposer/Classes/Router/Type Erasure/Boxes/FinderBox.swift

1
//
2
// RouteComposer
3
// FinderBox.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
struct FinderBox<F: Finder>: AnyFinder, CustomStringConvertible {
17
18
    let finder: F
19
20
    init?(_ finder: F) {
304x
21
        guard !(finder is NilEntity) else {
304x
22
            return nil
84x
23
        }
220x
24
        self.finder = finder
220x
25
    }
220x
26
27
    func findViewController(with context: AnyContext) throws -> UIViewController? {
193x
28
        let typedContext: F.Context = try context.value()
193x
29
        return try finder.findViewController(with: typedContext)
193x
30
    }
193x
31
32
    var description: String {
158x
33
        String(describing: finder)
158x
34
    }
158x
35
36
}