-1

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

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
rocket_moon
  • 309
  • 4
  • 18

1 Answers1

1

You have to add var window: UIWindow? property in AppDelegate.swift. You can refer to this link

The app delegate must implement the window property if it wants to use a main storyboard file swift