问题描述
我正在尝试从SceneDelegate推送模式。在模式推送运行之前,一切都很好。
我收到下面的错误,Xcode说变量imagePreview和DownloadURL为nil。是的,这些变量是从firebase加载的,就像我打印它们一样。
2020-10-23 02:18:20.277808 + 0200 MyApp [30028:568894]致命错误:意外发现nil,同时隐式展开一个可选值:文件MyApp / DownloadViewController.swift,第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)
}
}
})
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)