vds_ios/VDS/Extensions/UIApplication.swift
Matt Bruce 6840412f25 added comments to the UIApplication extension
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-05-26 16:36:59 -05:00

36 lines
1.0 KiB
Swift

//
// UIApplication.swift
// VDS
//
// Created by Matt Bruce on 4/14/23.
//
import Foundation
import UIKit
extension UIApplication {
/// Helper method to find the top most viewcontroller in the app
/// - Parameter controller: UIViewController to test against
/// - Returns: Found top most UIViewController
public class func topViewController(controller: UIViewController? = UIApplication.shared.windows.first?.rootViewController) -> UIViewController? {
if let nav = controller as? UINavigationController {
return topViewController(controller: nav.visibleViewController)
}
if let tab = controller as? UITabBarController {
if let selected = tab.selectedViewController {
return topViewController(controller: selected)
}
}
if let presented = controller?.presentedViewController {
return topViewController(controller: presented)
}
return controller
}
}