【发布时间】:2020-04-30 03:58:37
【问题描述】:
我的 Swift 程序因致命错误而崩溃,即使使用 GUARD 语句,也会说“Unexpectedly found nil while implicitly unwrapping an Optional value”。谁能帮忙告诉我为什么,我该如何解决?代码如下:
var page: Page? {
didSet{
guard let unwrappedPage = page else { return }
NameLabel.text = unwrappedPage.dishName
Image.image = UIImage(named: unwrappedPage.imageName)
contentText.text = unwrappedPage.ingredient
contentText.text = unwrappedPage.instruction
}
}
【问题讨论】:
-
你想做什么?
-
如果
NameLabel为 nil,而设置为 IBOutlet 非 nil... 或Image。或contentText.
标签: swift fatal-error guard