草庐IT

不符合

全部标签

swift - 类型 'NSFastEnumerationIterator.Element'(又名 'Any')不符合协议(protocol) 'AnyObject'

我正在尝试将我的应用程序更新到Swift3.0,但遇到了错误:Type'NSFastEnumerationIterator.Element'(又名'Any')不符合协议(protocol)'AnyObject'在线:self.friends.append(Friend(userName:(detailDataasAnyObject).value["userName"]as!String,phoneNumber:detailData.value["phoneNumber"]as!String,status:"Friend",statusSort:2,name:detailData.val

以错误类型作为参数的 iOS AWS 协议(protocol)方法导致协议(protocol)不符合

我正在使用AWSMobileHub为我用Swift编写的iOS应用程序实现登录。直到本周,它都运行良好,但更新到Xcode9.1导致出现几个构建错误。我还有2个错误。两者都涉及专门调用协议(protocol);“AWSSignInDelegate”和“AWSCognitoIdentityPasswordAuthentication”。extensionSignInVC:AWSSignInDelegate{funconLogin(signInProvider:AWSSignInProvider,result:Any?,error:Error?){//Code}}extensionSign

swift - 检查是否符合 Swift 中关联类型的协议(protocol)

在类似情况下,如何检查对象是否符合协议(protocol)“Representable”?protocolRepresentable{associatedtypeRepresentTypevarrepresentType:RepresentType{getset}}classA:UIView,Representable{enumRepresentType:String{caseatype="isa"}varrepresentType:RepresentType=.atype}classB:UIView,Representable{enumRepresentType{casebtype(

swift - 符合 Decodable 的类不需要初始化器

我目前正在研究Decodable、Encodable和friend,试图理解它背后的“魔法”。以下是我发现不寻常的一件事:classPerson:Decodable{varname:Stringvarage:Int}编译器欣然接受。如果我将它定义为struct我会理解它;编译器为struct创建隐式初始化程序。但是为什么会这样呢? 最佳答案 编译器还会为符合Encodable和Decodable的类型创建默认实现,只要它们的所有属性都是同样符合的类型。来自此处的原始提案:https://github.com/apple/swift-

swift - 关联类型符合协议(protocol)和依赖注入(inject)问题

我正在研究依赖注入(inject),目前正在更新我的项目以利用它。但是,我在关联类型和协议(protocol)符合方面遇到了问题。我创建了一个快速演示项目,并创建了一些协议(protocol)和扩展,以便符合我的协议(protocol)ViewModelBased的ViewController必须实现关联类型。理想情况下,我希望此关联类型符合viewModel。这是我目前所拥有的protocolViewModel{associatedtypeServicesinit(withServicesservices:Services)}protocolViewModelBased:class{

ios - 类型 'Any' 不符合协议(protocol) 'Equatable' 尝试符合可等式泛型集时

我正在尝试创建一个支持一组类型(Int、Float、可能是字符串,有时可能是Vec4矩阵)的基本结构。我已经构建了一个基本结构并将其符合Hashable,将类型设置为Equatable,但现在我需要在Set中使用这个新结构。这一行:structAdjustmentSet:Set>我声明Set的结构的地方是抛出Type'Any'doesnotconformtoprotocol'Equatable'这当然是显而易见的,但我不知道如何在这里实际定义一个有效的类型(我尝试了T:Equatable、Equatable,但没有任何效果)。structBaseAdjustment:Hashable{

ios - 类型 'String?' 不符合协议(protocol) '_CollectionType'

vardesc=item.itemDescriptionletregex:NSRegularExpression=NSRegularExpression(pattern:"",options:NSRegularExpressionOptions.CaseInsensitive,error:nil)!letrange=NSMakeRange(0,countElements(desc))lethtmlLessString:String=regex.stringByReplacingMatchesInString(desc,options:NSMatchingOptions.allZeros

swift - 扩展基础类以符合 Swift 协议(protocol)

我正在尝试定义一个协议(protocol),我想为其添加对几个基础类以及我自己的一些自定义类型的一致性。我首先尝试使用协议(protocol)中的便利初始值设定项来执行此操作,但是doesnotseempossible.我读了linkedthread在Apple开发者论坛上,他们讨论了使用返回类型Self的类方法,但我无法弄清楚如何去做。typealiasJSONObject=AnyObjectprotocolJSONParseable{staticfuncfromJSONObject(jsonObject:JSONObject)throws->Self}extensionNSURL:

objective-c - Swift 无法将符合协议(protocol)的类作为函数参数传递给驻留在 Objective-C 文件中的函数

大家好,我是Swift的新手,但对Objective-C很有经验。我有一个项目同时使用Swift和Objective-C文件(桥接和所有)。假设我有一个名为“fooProtocol”的协议(protocol)和一个实现它的类“foo”。我正在尝试将Swift文件中类型为“fooProtocol”的对象作为参数传递给Objective-C文件中的函数。这是“tester”类中的Objective-C函数:-(void)setWithFoo:(id*)_foo{}这是Swift代码:varmyObject:fooProtocol=foo.init()varobjcObject:tester

arrays - 将符合多种协议(protocol)的类型转换为单一协议(protocol)

我很难让Swift理解符合两种协议(protocol)的对象数组与符合其中一种协议(protocol)的数组相同。假设我有两个协议(protocol),Identifiable和Namable:protocolIdentifiable{varidentifier:Int{get}}protocolNamable{varname:String{get}}还有两个函数将打印有关符合这些协议(protocol)的对象数组的信息:funcprintIdentifiers(itemsToPrint:[Identifiable]){for(itemNumber,item)initemsToPrin