get presented view controller swift
// MARK: UIApplication extensions
extension UIApplication {
class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopViewController(base: nav.visibleViewController)
} else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
return getTopViewController(base: selected)
} else if let presented = base?.presentedViewController {
return getTopViewController(base: presented)
}
return base
}
}
// How to use
if let topVC = UIApplication.getTopViewController() {
topVC.view.addSubview(forgotPwdView)
}
Also in Swift:
- swift collection view check if you are at the bottom
- How to control the line spacing in UILabel
- swiftui font color
- Failure Reason: SecurityUser Info: {DVTRadarComponentKey = 855031;RawLLDBErrorMessage = Security
- send email with swiftmailer symfony
- rotate image animated swift
- navigationviewcontroller setviewcontrollers swift
- power swift
- swift ns_enum generic name
- Resizing UITableView to fit content
- generate hmac swift
- disable commit editing style swift
- how to print hello world in swift
- swift email composer
- swift how to sort array
- swift completion handler
- hide status bar ios
- get files with file type swift
- swift initialize a view
- swift initialize array with size
- filter text list swiftui
- spacing in uitextfield
- swift remove all pins from mapkit
- array length swift