When I try to unwrap "var window" using "!" it shows the Optional value is nil.
Fatal error: Unexpectedly found nil while unwrapping an Optional value
var window: UIWindow?
// image to be animated
let backgroundImg = UIImageView()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// creating imageView to store background image "mainbg.jpg"
backgroundImg.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)
backgroundImg.image = UIImage(named: "mainbg.jpg")
self.window!.addSubview(backgroundImg)
return true
}
Has anyone else faced this problem and managed to fix it?
I'm using XCODE Version 11.3.1 with SWIFT 5. This