Added extensions to get current AppDelegate, rootNavigationController, currentViewController, ...

This commit is contained in:
dankito 2020-08-24 17:37:52 +02:00
parent 34d5fcb52d
commit 5bdc17e9ce
1 changed files with 33 additions and 0 deletions

View File

@ -3,6 +3,39 @@ import SwiftUI
import BankingUiSwift
extension AppDelegate {
public static var current: AppDelegate { UIApplication.shared.delegate as! AppDelegate }
}
extension SceneDelegate {
public static var currentWindow: UIWindow? {
UIApplication.shared.windows.first(where: { (window) -> Bool in window.isKeyWindow})
}
public static var currentScene: UIWindowScene? { currentWindow?.windowScene }
public static var rootViewController: UIViewController? {
currentWindow?.rootViewController
}
public static var rootNavigationController: UINavigationController? {
rootViewController as? UINavigationController
}
public static var currentViewController: UIViewController? {
rootNavigationController?.visibleViewController ?? rootViewController
}
public static var currentNavigationItem: UINavigationItem? {
currentViewController?.navigationItem
}
}
extension Customer : Identifiable {
public var id: UUID { UUID() }