草庐IT

optional_argument

全部标签

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 - 加载 NibNamed 时崩溃(_ :owner:options:)

我在CustomView.swift中实现了自定义UIView。然后,我尝试通过以下方式在另一个名为CustomClass.swift的类中实例化一个CustomView对象:NSBundle.mainBundle().loadNibNamed(String(CustomView),所有者:self,选项:nil)我得到以下异常:***NSForwarding:warning:object0x7faceb60e300ofclass'CustomClass'doesnotimplementmethodSignatureForSelector:--troubleaheadUnrecogni

swift : Useless default value for Optional?

我正在创建一个这样的函数:funcfoo(bar:UInt?=0){letdoSomething=someOtherFunc(bar!)}如果我向foo()传递一个nil值,我希望在解包时使用默认值0,而不是我遇到了常见错误unexpectedlyfoundnilwhileunwrappinganOptionalvalue我哪里错了? 最佳答案 默认值=0仅在您不提供参数时使用对于可选参数:funcfoo(bar:UInt?=0){println(bar)}foo(bar:nil)//nilfoo(bar:1)//Optional(

arrays - 计算 Int Optionals 数组中空值的数量

我刚刚开始使用Swift并使用可选项。使用generateRandomArrayOfIntsAndNils()后努力计算测试数组中的nils数这是我要采用的方法:letarray1:[Int?]array1=generateRandomArrayOfIntsAndNils()\vartotal=0foriinarray1{if(array1[i]==nil){total+=1}}print(total)如有任何建议或指导,我们将不胜感激。 最佳答案 你可以这样做:letcountNils=array1.filter({$0==nil

问题解决:vscode 提示【Cannot find module ‘vue’. Did you mean to set the ‘moduleResolution’ option to ‘node’

问题解决:vscode提示【Cannotfindmodule‘vue’.Didyoumeantosetthe‘moduleResolution’optionto‘node’,ortoaddaliasestothe‘paths’option?】通过create-vue创建Vue3的项目后,vscode红色波浪线提示【Cannotfindmodule‘vue’.Didyoumeantosetthe‘moduleResolution’optionto‘node’,ortoaddaliasestothe‘paths’option?】。拿这个提示语到网上查找解决方法,帖子博客基本都是这样说的:到tsco

swift : Cannot invoke 'filter' with an argument list of type '(@noescape (Int) throws -> Bool)'

我遇到了这个错误:funccompactCoords(coords:[Int])->[Int]{returncoords.filter({(value)->Boolinreturnvalue!=0})}无法使用类型为“(@noescape(Int)throws->Bool)”的参数列表调用“filter”感谢您的帮助! 最佳答案 您的代码在Xcode7.1中运行良好。您可能不小心尝试在Xcode6.x中运行此代码?你可以像这样缩短你的函数:funccompactCoords(coords:[Int])->[Int]{returnco

swift 错误 : cannot convert value of type 'Int32' to expected argument type 'Int32'

我正在尝试编写一对函数,将String转换为[UInt8]字节数组,然后再转换回来。作为[UInt8]->String函数的一部分,我试图将单个Int32转换为Character。letnum:Int32=5letchar=Character(_builtinUnicodeScalarLiteral:num)但是我遇到了这个奇怪的错误:error:cannotconvertvalueoftype'Int32'toexpectedargumenttype'Int32'letchar=Character(_builtinUnicodeScalarLiteral:num)^~~编辑:我设法使

Swift/IOS8 错误 : "fatal error: Can' t unwrap Optional. 无”

我知道这方面已经有几个问题,但我想不通。之前解决的问题表明“profileViewController”为零,但我不知道为什么会这样。UI完全是程序化的,没有IB。获取:"fatalerror:Can'tunwrapOptional.None"在以下代码中的pushViewController()上:classFavoritesViewController:UIViewController{init(nibNamenibNameOrNil:String?,bundlenibBundleOrNil:NSBundle?){super.init(nibName:nibNameOrNil,bu

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