草庐IT

Duck-typing

全部标签

xcode - swift 2.0 : Type of expression is ambiguous without more context (Using Parse)

我一直收到错误消息“表达式类型不明确,没有更多上下文”。我的代码如下:funcfetchUnviewedUsers(callback:([User])->()){PFQuery(className:"Action").whereKey("byUser",equalTo:(PFUser.currentUser()?.objectId)!).findObjectsInBackgroundWithBlock{(objects,error)->VoidinletseenIDS=map(objects,{$0.objectForKey("toUser")!})PFUser.query()!.wh

ios - Alamofire : Type of expression is ambiguous in . 获取

我正在尝试使用Alamofire框架进行简单的下载。就在我将下载代码粘贴到我的项目(swift2)中时,我在此Alamofire代码中收到此错误:Alamofire.download(.GET,"https://httpbin.org/stream/100",destination:destination).progress{bytesRead,totalBytesRead,totalBytesExpectedToReadinprint(totalBytesRead)//ThisclosureisNOTcalledonthemainqueueforperformance//reason

Swift Vapor 和模块;如何区分两个重叠的 'type symbols'

我希望将一些(iOS)客户端代码重新使用到示例Vapor服务器端项目中。相关代码依赖于SwiftyJSON功能,定义为JSON结构;现在这个名称槽不是“免费”的,但已经在Vapor依赖的包中使用了(包名称也是JSON)。虽然我可以在我以前的客户端代码(如App.JSON)中指出我想要的JSON,但样板化到代码中的Controller也使用JSON。显然,像我一样将SwiftyJSON库文件放入App命名空间实际上覆盖了对VaporJSON的无模块引用。然后我尝试引用JSON.JSON,但它没有被识别。JSON是项目中定义编译好的框架。它不应该也隐含地定义一个模块名称吗?那么我怎样才能到

ios - 错误说 "value of type ' FIRDatabaseReference' 没有成员 'observe'“

这是我遇到错误的行:databaseHandle=ref.child("Posts").observe(.childAdded,withBlock:{(snapshot)inself.postData.append("")})下面是所有的代码...importUIKitimportFirebaseDatabaseclassFirstViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{@IBOutletvartableView:UITableView!varref:FIRDatabaseRef

ios - Swift 4 : Variable 'value' inferred to have type 'Void' , 这可能是意想不到的?

我正在尝试将存储在firebase存储中的图像的下载URL保存在数据库中。我看过here,和here,但是我收到以下错误:Cannotconvertvalueoftype'Void'totype'[String:String]'incoercion这发生在下面指示的行上:storageRef.downloadURL{(url,error)inguardletdownloadURL=urlelse{//Uh-oh,anerroroccurred!return}//databaseintegrationletref=Database.database().reference()letuse

ios - Swift 单元测试 : module name of object class causes type check to fail

我已经在我的项目中进行了几周的单元测试,到目前为止它们一直运行良好。我的一个新单元测试实例化了我的一个自定义ViewController。所述ViewController实例化并添加类型为CoolSearchBar的subview,这是我自己创建的一个类(.swift文件和.xib文件)。在上述ViewController中,我以编程方式加载了CoolSearchBar实例,然后将其添加到View层次结构中,如下所示:guardletsearchBar=Bundle.main.loadNibNamed(String(describing:CoolSearchBar.self),owne

ios - swift - 我可以比较 Any.Type 吗?

我定义了两种类型如下:我想定义一个函数“匹配”来比较两个KeyTypePairs并返回true或false取决于键和类型的匹配。protocolKeyTypePair:Hashable{typealiasvalvarkey:String{get}vartype:Any.Type{get}}publicstructKeyTypePairOf:KeyTypePair{typealiasval=Tlet_key:Stringlet_type:Any.Typepublicvarkey:String{get{return_key}}publicvartype:Any.Type{get{retur

objective-c - 一些for循环的问题 - - "Cannot subscript a value of type ' Double' with an index of type 'int' "errors

我在有索引的地方收到很多“无法使用‘int’类型的索引下标‘Double’类型的值”错误?阵列?像这样此代码取自Obj-C,并尽可能翻译成Swift,但我不熟悉某些语法。我清理了for循环,但一些Obj-C语法仍然存在。你能帮我清理/重构我的代码吗?importUIKitimportFoundationimportAVFoundationletminFramesForFilterToSettle=10enumCurrentState{casestatePausedcasestateSampling}classViewController:UIViewController,AVCaptu

swift 3 : Inheritance from non-named type

我有以下SSCIE:protocolFoo{associatedtypeBarassociatedtypeBaz:(Self.Bar)->VoidvarcurrentValue:Bar{get}}我想这样使用:funccall(foo:T,callback:@escapingT.Baz){DispatchQueue.main.async{callback(foo.currentValue)}}但是编译失败,报错:Inheritancefromnon-namedtype'(`Self`.Bar)'当我使用(Bar)->Void和(Foo.Bar)->Void时,这也无法编译。Sadly,

swift - 代码 9 : Cannot convert value of type '[String : Any]' to expected argument type '[NSAttributedStringKey : Any]?'

我有一个自定义的UIOutlineLabel类,它在标签内的文本周围绘制轮廓。自更新到Swift4后,我收到以下错误:无法将类型“[String:Any]”的值转换为预期的参数类型“[NSAttributedStringKey:Any]?”。我尝试将strokeTextAttributes更改为:as![NSAttributedStringKey:Any]但这会导致运行时错误。还有“UIOutlineLabelsetOutlineWidth已弃用并将在Swift4中删除”和“UIOutlineLabelsetOutlineColor已弃用并将在Swift4中删除”的Swift语言运行时