草庐IT

take_while

全部标签

swift - 从 Parse.com 检索 PFFile 时为 "unexpectedly found nil while unwrapping an Optional value"

我在检索存储在Parse.com中的PFFile时遇到问题letuser=PFUser.currentUser()letuserImageFile=user["profileImage"]asPFFileuserImageFile.getDataInBackgroundWithBlock{(imageData:NSData!,error:NSError!)->Voidiniferror==nil{ifimageData!=nil{letimage=UIImage(data:imageData)self.profileImage.image=image}}}错误从第二行开始。“profi

ios - 在 Swift ios 中使用 vImageBuffer_initWithCGImage 时出现 "fatal error: unexpectedly found nil while unwrapping an Optional value"

我正在使用SwiftiOS8并尝试将UIImage转换为vImage_Buffer以使用Accelerate.framework执行操作。我正在尝试使用vImageBuffer_initWithCGImage进行转换,这是我尝试过的代码:funcinitvImageBufferwithUIImage(image:UIImage)->vImage_Buffer{varCGImg:CGImageRef=sunset.CGImagevarinProvider:CGDataProviderRef=CGImageGetDataProvider(CGImg)varinBitmapData:CFDa

ios - swift - 警告 : Attempt to present * on * while a presentation is in progress

由于这个错误,我无法切换到另一个ViewController。我想在成功扫描二维码后切换到另一个ViewController。2015-01-2717:59:16.093*[5416:1860144]Warning:Attempttopresentonwhoseviewisnotinthewindowhierarchy!我的代码@IBActionfuncbtnQrCode(sender:AnyObject){reader.modalPresentationStyle=.FormSheetreader.delegate=selfreader.completionBlock={(resul

swift - 在 swift 中解析 JSON 抛出 'fatal error: unexpectedly found nil while unwrapping an Optional value'

我正在尝试获取json对象,但无法获取这是我的代码funcloadShots(completion:((AnyObject)->Void)!){varurlString="http://ip.jsontest.com/";letsession=NSURLSession.sharedSession()letshotsUrl=NSURL(string:urlString)vartask=session.dataTaskWithURL(shotsUrl!){(data,response,error)->Voidiniferror!=nil{println(error.localizedDes

while 语句中的 Swift 二元运算符

Swift的新手,小障碍。这段代码letviewH=self.view.frame.size.widthletboxH=viewH/60varcurY=0whilecurY抛出错误“二元运算符 最佳答案 小障碍,小修复。你的问题是curY是一个Int而右边的减法结果是一个CGFloat(什么是width还给你)。因此,您需要做的就是将curY也转换为CGFloat:varcurY=0asCGFloat或者:varcurY:CGFloat=0 关于while语句中的Swift二元运算符,我

swift - 通过按下按钮快速停止 for 或 repeat-while 循环

我需要弄清楚如何停止循环。我尝试了几种不同类型的循环,但最终结果是一样的——在循环进行时无法按下停止按钮。这是我到目前为止所拥有的...varstopButtonPressed=falsevarnumArray=[0,1,2,3,4,5,6,7,8,9]fornuminnumArray{print(num)sleep(2)ifstopButtonPressed{return}}很明显,按下的按钮将stopButtonPressed设置为true,但是同样...循环迭代时无法按下按钮。那么执行此操作的更好方法是什么?编辑@dasblinkinlight好的,所以我可以遵循您所说的逻辑,但

ios - fatal error : unexpectedly found nil while unwrapping an Optional value using AVAudio

我有两个项目,使用相同的代码,但下面一行:player=AVAudioPlayer(contentsOfURL:NSURL(string:fileLocation),error:&error)仅在一个项目中返回此错误:fatalerror:unexpectedlyfoundnilunwrappinganOptionalvalue另一个项目运行没有错误。我正在尝试播放声音。importUIKitimportAVFoundationclassViewController:UIViewController{varplayer:AVAudioPlayer=AVAudioPlayer()over

swift - SceneKit—— fatal error : unexpectedly found nil while unwrapping an Optional value when getting child node

所以我试图在我的SceneKit/Swift项目中使用3D对象(.dae1.4,使用Cinema4Dr13导出)。我留下了提供的代码并进行了更改:letscene=SCNScene(named:"art.scnassets/ship.dae")!适合我的:letscene=SCNScene(named:"art.scnassets/pyramid.dae")!我确实也将文件导入到它应该位于的项目中(在art.scnassets中)。我可以像默认飞船一样预览文件,所以这应该是正确的。我也改了:letship=scene.rootNode.childNodeWithName("ship",

swift - 在下面的 Swift 代码中,为什么程序到达 break 时会退出 while 循环?

在下面的Swift代码中,为什么程序到达break时会退出while循环?它不应该只退出if而不是while循环。varcokeLeft=7varfantasLeft=4while(cokeLeft>0){println("Youhave\(cokeLeft)Cokesleft.")cokeLeft=cokeLeft-1if(cokeLeft 最佳答案 中断通常退出最近的循环。while是一个循环。if不被认为是一个循环。这是相应的文档。FromtheIOSDeveloperLibrary:Abreakstatementendspr

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