Slather logo

Coverage for "KeyWindowProvider.swift" : 78.57%

(11 of 14 relevant lines covered)

RouteComposer/Classes/Finders/Stack Iterator/KeyWindowProvider.swift

1
//
2
// RouteComposer
3
// KeyWindowProvider.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
/// Returns key `UIWindow`
17
public struct KeyWindowProvider: WindowProvider {
18
19
    // MARK: Properties
20
21
    /// `UIWindow` instance
22
    public var window: UIWindow? {
360x
23
        let keyWindow: UIWindow?
360x
24
        if #available(iOS 13, *) {
360x
25
            keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow }
360x
26
        } else {
360x
27
            keyWindow = UIApplication.shared.keyWindow
!
28
        }
360x
29
        guard let window = keyWindow else {
360x
30
            assertionFailure("Application does not have a key window.")
!
31
            return nil
!
32
        }
360x
33
        return window
360x
34
    }
360x
35
36
    // MARK: Methods
37
38
    /// Constructor
39
    public init() {}
14x
40
41
}