草庐IT

Unwrapping

全部标签

ios - Obj-C 框架返回 nil,并使我的 Swift 代码崩溃并显示 'fatal error: unexpectedly found nil while unwrapping an Optional value'

我正在使用用Obj-C编写的第三方框架,它有一个功能:-(NSError*)generateModelForm如果此方法成功,它将返回nil。如果它不返回nil,它将返回一个错误,您可以检查该错误以进行调试。现在,当我使用桥接头在我的Swift文件中调用此函数并执行所有必需的操作时,它总是在第一行崩溃并显示“fatalerror:在展开可选值时意外发现nil”我的Swift代码:ifleterror=object.generateModelForm(){println("Error:\(error)")}else{println("Successfullygeneratedmodelf

swift - 出现任何 "fatal error: unexpectedly found nil while unwrapping an Optional value"时中断

我有一个庞大的代码库,我想解决错误“fatalerror:在展开可选值时意外发现nil”做到这一点的最佳方法是什么?我尝试同时添加:(在断点子窗口中)“添加Swift错误断点”“添加异常断点”但这并没有做到。这是否意味着nil在某些框架代码中而不是我的代码中? 最佳答案 解包选项被编译器翻译成对_getOptionalValue()的调用,它在nil值的情况下调用_preconditionFailure(),它被转换为对_fatalErrorMessage()的调用。所以需要为_fatalErrorMessage设置断点。这里的技巧

ios - fatal error : unexpectedly found nil while unwrapping an Optional value - Stanford Calculator

我正在ItunesU上观看斯坦福Swift讲师,但在理解上遇到了一些困难。讲师在某一时刻将String类型转换为Double类型。他是这样做的:returnNSNumberFormatter().numberFromString(display.text!)!.doubleValuedisplay.text是一个UILabel无论如何,当我这样做时,我的应用程序崩溃并且出现以下错误:fatalerror:unexpectedlyfoundnilwhileunwrappinganOptionalvalue当我这样输入字符串时:(display.text!asNSString).doubl

ios - reloadData() fatal error : unexpectedly found nil while unwrapping an Optional value

应用程序在该行崩溃classImageValueCell:UITableViewCell,UITableViewDelegate,UITableViewDataSource{@IBOutletweakvarimagesList:UITableView!varimageArray:NSArray!overridefuncawakeFromNib(){//super.awakeFromNib()//InitializationcodeimagesList.delegate=self;imagesList.dataSource=self;imageArray=NSArray()imagesL

ios - self.view?.presentScene : unexpectedly found nil while unwrapping an Optional value (Swift)

我正在尝试切换场景,但我的应用程序崩溃并出现此错误:crashcrashfatalerror:unexpectedlyfoundnilwhileunwrappinganOptionalvalue(lldb)这是我切换场景的代码:funcswitchscenes(){ifdisplay>=2{Player.removeFromParent()PlayerRight.removeFromParent()PlayerLeft.removeFromParent()fireHair.removeFromParent()fireHairRight.removeFromParent()fireHai

ios - Swift 中的 UIView 子类 : IBOutlet is found nil while unwrapping

我正在尝试通过子类化UIView在Swift中创建自定义View,并且我有一个名为MyViewPanel.xib的View板,其类已分配给我的自定义View。实现如下:importUIKit@IBDesignableclassMyCustomView:UIView{@IBOutletweakvartitle:UILabel!varquestion:Question{didSet{print("didsetquestion,titleis:\(question.title)")}}overrideinit(frame:CGRect){super.init(frame:frame)}req

ios - fatal error : unexpectedly found nil while unwrapping an Optional value in UITableViewCell

问了类似的问题here但这并不能为我解决这个问题。我添加了tableView在ViewController.使用它的数据源和委托(delegate)扩展类并为其添加所需的方法。然后我在此表中创建了一个原型(prototype)单元格(不是单独的.xib)并为此创建了一个类TableViewCell并收集了@IBOutlet:@IBOutletweakvartitleOfAccount:UILabel!@IBOutletweakvarlastModified:UILabel!@IBOutletweakvaraccountImage:UIImageView!@IBOutletweakvar

ios - ( swift )PrepareForSegue : fatal error: unexpectedly found nil while unwrapping an Optional value

细节ViewController:@IBOutletvarselectedBundesland:UILabel!表格ViewController:overridefuncprepareForSegue(segue:UIStoryboardSegue!,sender:AnyObject!){if(segue.identifier=="BackToCalculator"){varvc:FirstViewController=segue.destinationViewControllerasFirstViewControllervc.selectedBundesland.text="Test

ios - ( swift )PrepareForSegue : fatal error: unexpectedly found nil while unwrapping an Optional value

细节ViewController:@IBOutletvarselectedBundesland:UILabel!表格ViewController:overridefuncprepareForSegue(segue:UIStoryboardSegue!,sender:AnyObject!){if(segue.identifier=="BackToCalculator"){varvc:FirstViewController=segue.destinationViewControllerasFirstViewControllervc.selectedBundesland.text="Test

ios - 展开可选值时意外发现 nil

这个问题在这里已经有了答案:Whatdoes"Fatalerror:UnexpectedlyfoundnilwhileunwrappinganOptionalvalue"mean?(16个答案)关闭3年前。在我的应用程序中,我正在检查帖子是否有图片。为此,我正在使用:ifpictures[string]?!=nil{ifvarimage:NSData?=pictures[string]?{imageView.image=UIImage(data:image!)}}但是还是报错:fatalerror:unexpectedlyfoundnilwhileunwrappinganOptiona