草庐IT

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

swift - 在随机时间生成节点组合 waitForDuration :withRange and runBlock: in an SKAction sequence

我正在使用SpriteKit制作一个游戏,我的节点在屏幕顶部生成并掉落。但是,我希望这些节点以0.1到3秒之间的随机时间间隔生成。例如,第一个节点在1.3秒内生成,下一个节点在1.8秒内生成,然后是2.5秒,然后是0.8秒,等等。我不确定如何利用waitForDuration函数来执行此操作。我目前拥有的代码是:letwait=SKAction.waitForDuration(3,withRange:2)letspawn=SKAction.runBlock{addTears()}letsequence=SKAction.sequence([wait,spawn])self.runAct

ios - 捕获所有 "unexpectedly found nil while unwrapping an Optional value"

我有一个大型swift项目,从JSON获取大量数据。很难检查每一个数据和平是否为零。有没有办法捕获所有这些nils,以便我的应用程序在遇到意外nils时不会崩溃?或者我必须在我拥有的所有数据中使用“ifletvariable=...”!谢谢 最佳答案 坏消息:是的,您应该始终检查可选项。好消息:有比iflet更实用的快捷方式。例如。您可以提供合理的默认值(使用“nil-coalescingoperator”)。letitemID=jsonData["itemID"]as?NSNumber??0letstringVariable=js

swift - NS编码: Found nil unwrapping an Optional value

自从更新到Swift3后,我遇到了这个众所周知的崩溃,我自己无法解决...:fatalerror:unexpectedlyfoundnilwhileunwrappinganOptionalvalue*:在线self.isDefault=aDecoder.decodeObject(forKey:"BoxUserDefault_isDefault")作为!bool为什么现在会崩溃?这是我的课classBoxUserDefault:NSObject,NSCoding{varfrendlyName:Stringvarhostname:StringvarisDefault:Boolinit(fr

ios - swift fatal error : 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end."

我的swift程序一直有这个错误,我正在使用PHP和MySQL作为数据库。我要将数据从数据库显示到TableView。之前是可以的,但是在模拟器上运行了几次之后,我一直遇到同样的错误classHome:UIViewController,UITableViewDelegate,UITableViewDataSource{@IBOutletweakvarbtnaddclass:UIButton!@IBOutletvartableView:UITableView!varvalues:NSArray=[]funcget(){leturl=NSURL(string:"http://localho

swift - ImagePickerController 在设备和模拟器上返回 "image format with an unknown type"

我遇到了以下错误代码:Creatinganimageformatwithanunknowntypeisanerror。我已经看到了几个与此有关的线程,但是似乎没有一个可以解决我的问题。我做错了什么是我的代码publicfuncimagePickerController(_picker:UIImagePickerController,didFinishPickingMediaWithInfoinfo:[String:Any]){ifletimage=info[UIImagePickerControllerOriginalImage]as?UIImage{letdata=UIImagePN

ios - swift fatal error : unexpectedly found nil while unwrapping an Optional value uiimage

我在将UIImage分配给UIImageView的属性图像时出错funcconnectionDidFinishLoading(connection:NSURLConnection!){varerr:NSErrorvarjsonResult:NSDictionary=NSJSONSerialization.JSONObjectWithData(data,options:NSJSONReadingOptions.MutableContainers,error:nil)asNSDictionaryprintln("\(jsonResult)")ifjsonResult.count>0{let

ios - WKInterfaceTable 和 setNumberOfRows 崩溃 "unexpectedly found nil while unwrapping an Optional value"

我正在使用WatchKit,我有一个只有一个表的简单界面,但我只用了几行代码就出错了,也许我忘记了一些非常基本的东西。我的界面:表格内的行具有标识符:和自定义类:Controller由这段代码实现:importWatchKitimportFoundationclassActiveListController:WKInterfaceController{@IBOutletweakvartableView:WKInterfaceTable!overridefuncawakeWithContext(context:AnyObject?){super.awakeWithContext(cont

ios - Firebase 商店 : trying to store to local file gives an error

当我尝试按照文档中的示例从Firebase存储中存储文件时,我收到以下错误:Optional(ErrorDomain=FIRStorageErrorDomainCode=-13000"Anunknownerroroccurred,pleasechecktheserverresponse."UserInfo={object=ProfilePicture/Jf2dFzI7LZNzQkOkdFfa3UWQJyH2.jpg,bucket=mapit-1333.appspot.com,NSLocalizedDescription=Anunknownerroroccurred,pleasechec

swift - 核心数据 [NSSet intersectsSet :]: set argument is not an NSSet

我有两个关系表。在尝试保存产品的ShopItem类中:letproductEntity=NSEntityDescription.entityForName("Product",inManagedObjectContext:self.managedObjectContext!)product=Product(entity:productEntity!,insertIntoManagedObjectContext:self.managedObjectContext!)ifletproduct_title:String=jsonObj["product_title"]as?String{pr