草庐IT

any_option

全部标签

ios - Swift 中的 UIPickerView 子类 : error optional value in viewForRow

我想继承UIPickerView以创建自定义DatePicker。我试过了,但是Swift中有一个错误说:unexpectedlyfoundnilwhileunwrappinganOptionalvalue在这一行:(view.viewWithTag(1)asUILabel).text=array[row]代码如下:classMyPickerView:UIPickerView,UIPickerViewDataSource,UIPickerViewDelegate{letarray=["one","two","three"]requiredinit(coderaDecoder:NSCod

ios - Swift:比较隐式展开的可选结果为 "unexpectedly found nil while unwrapping an Optional values"

如果得到这个类并且想根据值比较它的实例classLocationOption:NSObject{varname:String!varradius:Int!varvalue:String!overridefuncisEqual(object:AnyObject?)->Bool{ifletotherOption=objectas?LocationOption{return(self.name==otherOption.name)&&(self.radius==otherOption.radius)&&(self.value==otherOption.value)}returnfalse}}

swift - 将 Any 转换为数组

这是我尝试使用的代码structA{varx:Int=0}structB{vary:Int=0}varc:[String:Any]=["a":[A()],"b":[B()]]for(key,value)inc{letarr=valueas![Any]}它只是抛出异常。尝试将Any转换为[Any]时引发运行时异常。我想要实现的主要目标是遍历Any的元素,如果Any是数组的话。对我来说,将Any转换为[Any]是很自然的,但由于某种原因,它不起作用。那么我怎样才能swift做到这一点呢?我看到了一些将Any转换为[A]或[B]的变通方法,但我的情况并非如此,因为数组可以只包含任意结构。

swift - 为什么 optional 不发出警告或要求强制展开?

structSomeStruct{varoptVar:String?varnonOptVar:String="Hello"varoptvar2:String!}letobj2=SomeStruct(optVar:"a",nonOptVar:"b",optvar2:"c")leta=obj2.optVar//whyitisnotaskingforforceunwrapingletb=obj2.nonOptVarletc=obj2.optvar2print(a)print(b)print(c)请分享您对此的看法。但是,虽然我通常在项目中使用可选项,但它会发出警告'从String隐式强制表达

swift - 线程 10 : Fatal error: Unexpectedly found nil while unwrapping an Optional value

我正在尝试进行服务调用以获取用户详细信息,但出现此错误:线程10:fatalerror:在展开可选值时意外发现nil从这段代码:leturlString="http://myURL.com/getInfo/getAccountTransactions/{accountPublicKey}"print(urlString)letrequestUrl=URL(string:urlString)letrequestURL=URLRequest(url:requestUrl!)当我将代码包装在一个守卫中时,让代码不会被执行,因为它发现nil,我不确定为什么,因为URL字符串永远不会是nill,

swift - hitTest(_ :options:) don't recognize nodes behind ARKit planes

我将一个物体放在墙上,然后尝试识别点击它,但HitTest返回0个物体。当我改变物体的Z位置并将其放置在靠近凸轮的位置时,它可以很好地识别,但这不是解决方案,因为平面总是在变化并且它可以随时覆盖物体。如何使hitTest正常工作并识别平面后面的节点?或者,也许,我使用了错误的方法?fileprivatefuncaddNode(atPointpoint:CGPoint){lethits=sceneView.hitTest(point,types:.existingPlaneUsingExtent)ifhits.count>0,letfirstHit=hits.first,letorigi

swift - 为什么我们需要显式地将可选类型转换为 Any?

根据Apple文档,TheAnytyperepresentsvaluesofanytype,includingoptionaltypes.SwiftgivesyouawarningifyouuseanoptionalvaluewhereavalueoftypeAnyisexpected.IfyoureallydoneedtouseanoptionalvalueasanAnyvalue,youcanusetheasoperatortoexplicitlycasttheoptionaltoAny,asshownbelow.varthings=[Any]()things.append(3)/

swift - println 字典有 "Optional"

考虑这个片段:letinterestingNumbers=["Prime":[2,3,5,7,11,13],"Fibonacci":[1,1,2,3,5,8],"Square":[1,4,9,16,25],]println(interestingNumbers["Square"])letindividualScores=[75,43,103,87,12]println(individualScores)控制台输出:可选([1,4,9,16,25])[75,43,103,87,12]为什么字典里有一个“Optional”? 最佳答案

uitableview - fetchedResultsController核心数据 fatal error : unexpectedly found nil while unwrapping an Optional value

我知道有无数的问题都出现了同样的错误,但似乎没有一个解决方案有效。我想制作一个博客阅读器应用程序,用于从CoreData保存和获取数据。我能够将JSON结果保存到CoreData中,但是当我尝试检索它以在tableView中显示时,它崩溃并显示fatalerror:unexpectedlyfoundnilwhileunwrappinganOptionalvalueonlineletentity=NSEntityDescription.entityForName("博客",inManagedObjectContext:self.managedObjectContext!)这是我的代码:i

iOS/swift : Can't assign optional String to UILabel text property

UILabel有一个文本属性,它是一个可选的字符串,但它的行为似乎像一个隐式展开的可选。为什么我不能给它分配另一个可选字符串?谢谢。@IBOutletweakvartweetContent:UILabel!...varunopt:String="foo"varopt:String?="bar"varopt2:String?opt2=opt//Worksfinecell.tweetContent.text?=unopt//Worksfinecell.tweetContent.text?=opt//Compileerror:Valueofoptionaltype'String?'notun