I'm trying to push a modal from the SceneDelegate. It all works well until the modal push runs.
I'm gettin the error below, and Xcode says that the variables imagePreview and DownloadURL are nil. Yes the variables are loaded from firebase, as if I print them it works.
2020-10-23 02:18:20.277808+0200 MyApp[30028:568894] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value: file MyApp/DownloadViewController.swift, line 29
func pushFile(id: String) {
self.window?.rootViewController = DownloadViewController()
ref = Database.database().reference(withPath: "files")
ref.child(id).observeSingleEvent(of: .value, with: { [self] (snapshot) in
let value = snapshot.value as? NSDictionary
let preview = value?["a"] as? String ?? ""
let downloadURL = value?["d"] as? String ?? ""
if let tabBarController = window?.rootViewController! as? UIViewController { //use of unresolved identifier 'window'
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let vc = storyboard.instantiateViewController(withIdentifier: "download") as? DownloadViewController {
vc.imagePreview = preview
vc.downloadURL = downloadURL
tabBarController.present(vc, animated: true)
}
}
})
}