I'm using MBProgressHUD to show a loader, and when acessing the app window the value in nil and the app crashes. I already imported the MBProgressHUD and created a variable appDelgate equals to UIApplication.shared.delegate as! AppDelegate, and when accessing that variable window! I get the follwing error: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Code:
import MBProgressHUD
let appDelgate = UIApplication.shared.delegate as! AppDelegate
MBProgressHUD.showAdded(to: appDelgate.window!, animated: true)
I cant seem to find what I missing here