草庐IT

Do-While

全部标签

ios - 当 String 不符合错误时抛出的函数命中 do catch block 时如何获得正确的错误?

importFoundationenumErrorScenarios:Error{caseinvalidAgecaseinvalidEmailcaseincorrectData}funcage(age:Int)throws{ifage我在这里使用docatchblock来捕获invalidAge错误场景,我不太确定这是否正确?当我在Playground上跑时,catchblock永远不会被击中。do{tryage(age:-23)}catch{throwErrorScenarios.invalidAge}这里作为docatchblock的替代方案,我通过将其设为可选来处理错误,因此我猜

uitableview - swift - 错误 : unexpectedly found nil while unwrapping an optional value

我一直在用Swift制作应用程序,但我的TableViewController类中一直出现错误。我找不到任何方法来解决此问题并不断收到此错误:overridefunctableView(tableView:UITableView?,cellForRowAtIndexPathindexPath:NSIndexPath!)->UITableViewCell!{letcell:TextTableViewCell=tableView!.dequeueReusableCellWithIdentifier("Cell",forIndexPath:indexPath!)asTextTableView

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

ios - swift 3.0 : argument labels '(_:) do not match any available overloads

我刚刚转换为Swift3,我需要有关此错误的帮助。昨天我转换为swift3时遇到了这个错误,这个完整的代码运行良好。我试一下?在其中,但它根本没有修复错误,它保持不变。importFoundationimportAVFoundationclassAudioHelper:NSObject,AVAudioPlayerDelegate{varplayer:AVAudioPlayer?classvardefaultHelper:AudioHelper{structStatic{staticletinstance:AudioHelper=AudioHelper()}returnStatic.in

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