-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIAlertController+Extension
25 lines (22 loc) · 1.05 KB
/
UIAlertController+Extension
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
extension UIAlertController {
func show() {
present(animated: true, completion: nil)
}
func present(animated: Bool, completion: (() -> Void)?) {
if let rootVC = UIApplication.shared.keyWindow?.rootViewController {
presentFromController(controller: rootVC, animated: animated, completion: completion)
}
}
private func presentFromController(controller: UIViewController, animated: Bool, completion: (() -> Void)?) {
if let navVC = controller as? UINavigationController,
let visibleVC = navVC.visibleViewController {
presentFromController(controller: visibleVC, animated: animated, completion: completion)
} else
if let tabVC = controller as? UITabBarController,
let selectedVC = tabVC.selectedViewController {
presentFromController(controller: selectedVC, animated: animated, completion: completion)
} else {
controller.present(self, animated: animated, completion: completion);
}
}
}