简体   繁体   English

Xcode Swift:appDelgate.window! is nil :致命错误:在解开可选值时意外发现 nil

[英]Xcode Swift : appDelgate.window! is nil : Fatal error: Unexpectedly found nil while unwrapping an Optional value

I'm using MBProgressHUD to show a loader, and when acessing the app window the value in nil and the app crashes.我正在使用 MBProgressHUD 来显示加载程序,并且在访问应用程序窗口时,值为 nil 并且应用程序崩溃。 I already imported the MBProgressHUD and created a variable appDelgate equals to UIApplication.shared.delegate as!我已经导入了 MBProgressHUD 并创建了一个变量 appDelgate 等于 UIApplication.shared.delegate as! AppDelegate, and when accessing that variable window! AppDelegate,并在访问该变量窗口时! I get the follwing error: Fatal error: Unexpectedly found nil while unwrapping an Optional value我收到以下错误:致命错误:在展开可选值时意外发现 nil

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我似乎无法在这里找到我缺少的东西

You have to add var window: UIWindow?你必须添加 var window: UIWindow? property in AppDelegate.swift. 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 如果应用程序委托要快速使用主故事板文件,则它必须实现 window 属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 快速致命错误:解开Optional值时意外发现nil - swift fatal error: unexpectedly found nil while unwrapping an Optional value Swift致命错误:解开Optional值时意外发现nil - Swift fatal error: unexpectedly found nil while unwrapping an Optional value 致命错误:在Swift 3中解开Optional值时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value in Swift 3 SWIFT-致命错误:解开可选值时意外发现nil - SWIFT - fatal error: unexpectedly found nil while unwrapping an Optional value Swift:致命错误:在展开可选值时意外发现nil - Swift : fatal error: unexpectedly found nil while unwrapping an Optional value Xcode控制台错误消息:“致命错误:在展开可选值时意外发现nil”(快速) - Xcode console error message: 'fatal error: unexpectedly found nil while unwrapping an Optional value' (Swift) xcode9 swift4致命错误:展开一个可选值时意外发现nil - xcode9 swift4 Fatal error: Unexpectedly found nil while unwrapping an Optional value Swift-致命错误:解开Optional值时意外发现nil - Swift - Fatal error: unexpectedly found nil while unwrapping an Optional values UIImagePickerController致命错误:解开可选值时意外发现nil - UIImagePickerController fatal error: unexpectedly found nil while unwrapping an Optional value 致命错误:在didDeselectRowAt中解开Optional值时意外发现nil - fatal error: unexpectedly found nil while unwrapping an Optional value in didDeselectRowAt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM