草庐IT

original_options

全部标签

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 - 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

Swift 结构扩展函数 - "Cannot assign to ' origin' in 'self' "

Swift中的结构可以包含函数并且可以有扩展。凉爽的!看起来是一种使此函数可用于更多类并减少参数传递的巧妙方法。这是函数最初在mapViewController中的样子:funcexpandTrackRectToCoordinate(coordinate:CLLocationCoordinate2D){letpoint=MKMapPointForCoordinate(coordinate)letnewRect=MKMapRectMake(point.x,point.y,0.0,0.0)ifMKMapRectIsNull(trackRect){trackRect=MKMapRectMak

ios - mapView.addAnnotation() 表示 "unexpectedly found nil while unwrapping an Optional value"

我尝试从tableView单元格的地址转到mapView并在map上显示图钉。我确定我的代码中的所有内容都不为零。但是Xcode说我的oldValue是nil(在didSet{}中)。我不知道如何解决它。以下是我的代码:classMapViewController:UIViewController,MKMapViewDelegate{@IBOutletweakvarmapView:MKMapView!{didSet{mapView.mapType=.StandardmapView.delegate=self}}varlocation:CLLocation?{didSet{clearWa

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

我是Swift的新手,一直在尝试围绕可选值进行思考。据我所知——虽然我可能错了——变量可以是可选的,因此包含一个nil值,这些必须在代码中考虑。每当我在我的应用程序中点击“保存”按钮时,我都会收到错误消息:“fatalerror:在展开可选值时意外发现nil”。@IBActionfuncsaveTapped(sender:AnyObject){//codetosavefilluptoParsebackend//ifvariableisnotnilifletusername=PFUser.currentUser()?.username{//setusernameequaltocurren

ios - Swift - 在将项目添加到数组时解包 Optional 值时意外发现 nil

我有一个这样的数组:vargestureArray:Array!我正在尝试像这样向这个数组添加项目:forgestureinwebview.scrollView.gestureRecognizers!{gestureArray.insert(gesture,atIndex:0)}print(gestureArray)但在尝试添加第一项后出现此错误:unexpectedlyfoundnilwhileunwrappinganOptionalvalue当我打印每个手势时,它们看起来像这样:;target=)>>;target=)>>;target=)>> 最佳答案

ios - 为什么 Swift 打印 "Optional(455 bytes)"

我正在开发一个天气应用程序,并尝试从API获取数据。但是,当我输入城市名称并按回车键时,Swift会打印出一条消息“可选(455字节)”,不知道出了什么问题。importFoundationprotocolWeatherServiceDelegate{funcsetWeather(weather:Weather)}classWeatherService{vardelegate:WeatherServiceDelegate?funcgetWeather(city:String){letpath="http://api.openweathermap.org/data/2.5/weather