草庐IT

gravity_value_t

全部标签

swift - 在 [String:String] 中转换 [(key : String, value: String)]

我想在[String:String]中转换[(key:String,value:String)]可以吗?如果是的话我怎么做?谢谢varKeyValuePair:[(key:String,value:String)]=[(key:"20170104",value:"143.65"),(key:"20170105",value:"140.78"),(key:"20170106",value:"150.23")]在vardictionary:[String:String]=["20170104":"143.65","20170105":"140.78","20170106":"150.23"

swift - '(key : AnyObject, value: AnyObject )' does not have a member named ' 下标'

我有一个类似于thisquestion的问题,但那里的答案对我没有帮助。我有这些代码行:varid=item["id"]as?String??""varname=item["name"]as?String??""varpic=item["pic"]as?String??""对我来说,这些代码行几乎是一样的。对于Xcode,这是另一回事。第一行没问题。后两行生成此错误:'(key:AnyObject,value:AnyObject)'doesnothaveamembernamed'subscript'这里为大家提供更多背景信息:classfuncgetFromJson(json:NSDi

swift - Xcode 崩溃试图将数组作为 'value' 添加到字典(使用 Playground 文件)

经过多次实验和多次崩溃,我还是想不通:vardictionary:Dictionary=["A":"ValA"]vararray=["A","B"]dictionary["Ar"]=/*XcodecrashassoonasItype'a'andautocompletebringsupmy'array'*/我尝试了很多不同的方法,包括添加一个空数组(部分有效),但是只要我向该数组添加一些东西,Xcode就会崩溃。Apple确实提到“Swift数组特定于它们可以存储的值的种类。”,但这不应该冲突。类型“Any”仍然是一种类型。当然,编译器警告是人们所期望的,但话又说回来,这是测试版。

ios - 使用 Swift 的 Alamofire - "Could not cast value of type ' Swift._SwiftDeferredNSArray' (ox10a75ebb0) 到 'Photomania.PhotoInfo' (0x107ee7b90)。”

运行OSXElCap开发测试版、iOS9.0、Xcode7.0GM我正在关注RayWenderlich教程(http://www.raywenderlich.com/85080/beginning-alamofire-tutorial),但确实遇到了一些问题。在我创建请求路由器之前,我的应用程序无法运行。它构建正确,然后一旦开始加载,我就会在标题中看到调试器短语。构建错误描述为“Thread1:signalSIGABRT”。概述的行是:letimageURL=(photos.objectAtIndex(indexPath.row)as!PhotoInfo).url这是PhotoBrow

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

swift - 字典<AnyHashable : Any> where Any may hold nil value in Swift 3

有人可以解释为什么这在Swift3中有效吗?vardict:[AnyHashable:Any]letb:AnyObject?=nilletc=basAnydict=["a":"aa","b":c]如果我测试dict["b"]==nil它返回错误。它应该是正确的吗? 最佳答案 您遇到了嵌套的可选值。如果字典包含E类型,则字典访问方法返回类型E?的值,如果存在该值,则返回nil。在您的例子中,您创建了一个字典,其中的值是可选的。所以上面的E类似于Any?。这意味着getter的返回值是E?即Any??在你的情况下,dict["b"]返回

ios - swift 3 : How to access the value of matrix_float3x3 in a 48-byte CFData?

我正在尝试访问此answer之后的内在矩阵.通过运行下面的指令,我能够得到一个48字节的AnyObject。,我进一步将其转换为CFData.letcamData=CMGetAttachment(sampleBuffer,kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix,nil)但是,我检查了CMSampleBuffer.h中sampleBuffer的输出:/*!@constantkCMSampleBufferAttachmentKey_CameraIntrinsicMatrix@abstractIndicatesthe3x3came

swift - 无法使用类型为 (Int, @value Int) 的参数列表调用 "+="

我有一个Transaction类,它有一个类型为Int的varamount。我想从另一个类访问它,我有一个交易数组并对它们的所有金额求和。所以我有这段代码funccomputeTotal()->Int{lettotal=0fortransactionintransactions{//gettheamountsofeachandsumallofthemuptotal+=transaction.amount}returntotal}但它给了我一个错误无法使用类型为(Int,@valueInt)的参数列表调用“+=”是什么原因造成的?我知道在Swift中两个操作数必须是同一类型,但在我的代码

ios - 为什么我会收到此错误 : Result values in '? :' expression have mismatching types '[String]?' and 'String'

所以我是swift的新手,我正在尝试使用谷歌地图。我无法弄清楚为什么这条线有效:让state=p?.administrativeArea!=nil?p?.administrativeArea:"nil6"但不是这一行:让areaOfInterest=p?.areasOfInterest!=nil?p?.areasOfInterest:"nil7"我在areaOfInterest行收到此错误消息:'?中的结果值:'表达式有不匹配的类型'[String]?'和“字符串”提前致谢。CLGeocoder().reverseGeocodeLocation(userLocation){(place