How do I get the keyWindow reference in a swift app?

I came to this question when I was searching for getting window in swift. If you want to get window instead of keyWindow, try this (Swift 2):

if let app = UIApplication.sharedApplication().delegate as? AppDelegate, let window = app.window {
    MBProgressHUD.show(text, view:window)
}

Updated for Swift 3: (Thanks @Trevor)

if let app = UIApplication.shared.delegate as? AppDelegate, let window = app.window {
    MBProgressHUD.show(text, view:window)
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)