Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import UIKit
extension UIViewController {
func getForegroundAlertController() -> UIAlertController? {
var viewController = UIApplication.sharedApplication().keyWindow?.rootViewController
while let controller = viewController?.presentedViewController {
if controller is UIAlertController {
viewController = controller
guard let alert = viewController as? UIAlertController else {
return nil
return alert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment