From bc3b9794bb7afbedd2da175770c371e938647831 Mon Sep 17 00:00:00 2001 From: Gary Tokman Date: Mon, 3 May 2021 18:44:44 -0400 Subject: [PATCH] fix: random warnings in the project --- .../ExtensionKit/UIKit/UIApplication.swift | 24 +++++++++++++------ .../ExtensionKit/UIKit/UIViewController.swift | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Sources/ExtensionKit/UIKit/UIApplication.swift b/Sources/ExtensionKit/UIKit/UIApplication.swift index c086494..3e5caf5 100644 --- a/Sources/ExtensionKit/UIKit/UIApplication.swift +++ b/Sources/ExtensionKit/UIKit/UIApplication.swift @@ -1,11 +1,21 @@ #if canImport(UIKit) -import UIKit + import UIKit #endif public extension UIApplication { - + + /// Application key window + static let keyWindow = UIApplication + .shared + .connectedScenes + .filter { $0.activationState == .foregroundActive } + .compactMap { $0 as? UIWindowScene } + .first?.windows + .filter { $0.isKeyWindow } + .first + /// Open application settings func openSettings() { if let url = URL(string: UIApplication.openSettingsURLString), canOpenURL(url) { @@ -16,7 +26,7 @@ public extension UIApplication { } } } - + /// Opens application sheet for phonen number func openPhone(calling number: String) { if let url = URL(string: "tel://" + number) { @@ -27,7 +37,7 @@ public extension UIApplication { } } } - + /// Find My Facebook ID: https://findmyfbid.com/ /// - Parameters: /// - name: Facebook name @@ -46,7 +56,7 @@ public extension UIApplication { UIViewController.getCurrentViewController()?.pushSafariViewController(urlString: "https://www.facebook.com/" + name) } } - + /// Launches the Instagram app and loads the Instagram user /// - Parameter name: Instagram username func openInstagram(name: String?) { @@ -63,7 +73,7 @@ public extension UIApplication { } } } - + /// Launches the Instagram app and loads the Instagram user /// - Parameter name: Instagram username func openInstagram(media: String?) { @@ -80,7 +90,7 @@ public extension UIApplication { } } } - + /// Open a map app with the given query. Orders: Google Map -> Apple Map /// /// - Parameter query: The query to search on the map. diff --git a/Sources/ExtensionKit/UIKit/UIViewController.swift b/Sources/ExtensionKit/UIKit/UIViewController.swift index 1771edd..a4b3e8c 100644 --- a/Sources/ExtensionKit/UIKit/UIViewController.swift +++ b/Sources/ExtensionKit/UIKit/UIViewController.swift @@ -210,7 +210,7 @@ public extension UIViewController { /// /// - Parameter base: `UIViewController` to search /// - Returns: Current `UIViewController` - class func getCurrentViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { + class func getCurrentViewController(base: UIViewController? = UIApplication.keyWindow?.rootViewController) -> UIViewController? { if let nav = base as? UINavigationController { return getCurrentViewController(base: nav.visibleViewController) }