From 5bdc17e9ceebb8cdcea3f084b31eca374c6e48f3 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 24 Aug 2020 17:37:52 +0200 Subject: [PATCH] Added extensions to get current AppDelegate, rootNavigationController, currentViewController, ... --- .../persistence/Extensions.swift | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift index 3a97d99b..882fc8ea 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift @@ -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() }