草庐IT

TYPE_SCROLL_INSENSITIVE

全部标签

swift - 泛型类型错误 : Cannot explicitly specialise a generic type

我正在尝试在RequestManager中创建一个通用函数通过ServiceManager将服务器接收到的JSON转换为指定类型.这是我的代码:请求管理器:typealiasResultResponseManager=(_data:AnyObject?,_error:ErrorPortage?)->VoidtypealiasSuccessResponseManager=(_success:Bool,_error:ErrorPortage?)->VoidtypealiasobjectBlock=(_object:T?,_error:ErrorPortage?)->Voidextensio

ios - 错误 : Invalid conversion from throwing function of type '(_) throws -> ()' to non-throwing function type '(DataSnapshot) -> Void'

这是我的代码:funcloadData(){ref.child(currentUserID!).observe(.childAdded){(snapshot)inletsnapshotValue=try?snapshot.valueas?[String:AnyObject]ifletitem=tryTableViewModel(id:snapshot.key,likeLabel:self.likeLabel,playLabelString:self.playLabelString,json:snapshotValue){self.items.append(item)}self.tabl

swift 4 : Cannot call value of non-function type '[Self.Element.Type]' when instantiating associated type array

我在这篇文章(https://www.uraimo.com/2016/01/06/10-Swift-One-Liners-To-Impress-Your-Friends/)中对Xcode9beta2Swift4做了一些练习,当时我在执行第1项时遇到错误。6:extensionSequence{typealiasElement=Self.Iterator.ElementfuncpartitionBy(fu:(Element)->Bool)->([Element],[Element]){varfirst=[Element]()varsecond=[Element]()forelinself

swift - 如何解决 "Argument type ' CustomStruct' does not conform to expected type 'Sequence' "

我试图使用下面的代码来洗牌一个由名为Card的简单自定义结构组成的数组。,我在cards.remove(at:randomIndex)处收到错误:Error:Argumenttype'Card'doesnotconformtoexpectedtype'Sequence'代码如下:varcards=[Card]()//declarethearrayvarshuffledCards=[Card]()for_incards.indices{letrandomIndex=Int(arc4random_uniform(UInt32(cards.count)))shuffledCards+=car

swift - 检查 Any.Type 是否符合 Swift 中的协议(protocol)

我想检查Any.Type的给定值是否符合Swift中的协议(protocol)。似乎可以通过调用class_conformsToProtocol()检查基于@objc的协议(protocol),但我不知道如何使用纯swift协议(protocol)检查它。//ObjC@objcprotocolMyObjcProtocol{}classMyObjcClass:NSObject,MyObjcProtocol{}class_conformsToProtocol(MyObjcClass.self,MyObjcProtocol.self)//true//SwiftprotocolMySwiftP

ios - Ios Swift 4 中的 TableView CheckMark 和 Uncheck With Scroll Up 仍然检查单元格值

TableViewCheckMarkCellValueRemovedAfterScrollingUpItwillFixTableViewinYouhavefaceaproblemmanytimestoCheckmarkafterscrollUpthenScrollDownToshowaYourCheckmarkcelliswillRemovedBecausecellisdequeueReusableCellSoThisProblemFix,youHavejustputYourcodeandSolvedYourProblem.AnyMoreHelpSoSendMassage.Thanky

swift - 接收 Swift 错误 : Cannot convert value of type '([PFObject]?, NSError)? Void' to expected argument type 'PFArrayResultBlock?'

我是swift和Xcode的新手,所以如果这是一个不好问的问题,我深表歉意。我正在和一个friend一起做一个项目,当我克隆这个项目时,一些解析框架没有被拉到我的机器上,我现在相信我知道为什么了。然后他把那些框架发给我。现在,当我重新启动项目时,我收到7个错误,这些错误都与我认为是解析引起的问题有关。我在所有7个错误中得到的错误是:([PFObject]?,NSError)?Void'toexpectedargumenttype'PFArrayResultBlock?它引用了这段代码中的第4行@IBActionfuncdeleteSubjectButton(sender:AnyObje

ios - Swift3 中的 "Cannot convert value of type"错误

我遇到了以下错误:使用Xcode-beta5和Swift。在测试版4中它工作正常。谁能帮帮我?extensionUIImageView{publicfuncimageFromUrl(_urlString:String){ifleturl=URL(string:urlString){letrequest=URLRequest(url:url)NSURLConnection.sendAsynchronousRequest(request,queue:OperationQueue.main){(response:URLResponse?,data:Data?,error:NSError?)-

ios - swift 和 Realm : Invalid use of '()' to call a value of non-function type 'module<Realm>'

我实际上是从Swift的官方Realm文档中复制和粘贴代码-但它无法编译:https://realm.io/docs/swift/latest/#adding-objects我正在使用Realm1.0.2文档确实自相矛盾-不同的Realm声明:letrealm=RLMRealm.defaultRealm()letrealm=Realm()letrealm=try!Realm()Realm是怎么回事?Realm和RLMRealm有什么区别?上面的第一行可以正常编译-但接下来的两行不会。 最佳答案 Iamliterallycopying

swift - 带有嵌套类的 Swift 4 上的 "instance member cannot be used on type"错误

我有一个带有嵌套类的类。我试图从嵌套类中访问外部类的变量:classThing{varname:String?vart=Thong()classThong{funcprintMe(){print(name)//error:instancemember'name'cannotbeusedontype'Thing'}}}然而,这给了我以下错误:instancemember'name'cannotbeusedontype'Thing'有没有一种优雅的方法来规避这种情况?我希望嵌套类能够像闭包一样捕获词法范围。谢谢 最佳答案 你可以这样做c