大佬教程收集整理的这篇文章主要介绍了ios – Swift扩展 – 必须在非专用泛型类型’Array’上声明约束扩展,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
typealias Mymodels = [Mymodel] struct Mymodel: Codable { let field1: String let field2: String let mySubModel: SubModel? enum CodingKeys: String,CodingKey { case field1 = "Field1" case field2 = "Field2" case mySubModel = "MySubModel" } } struct SubModel: Codable { let subModelField1: String let subModelField2: String enum CodingKeys: String,CodingKey { case subModelField1 = "SubModelField1" case subModelField2 = "SubModelField2" } }
我想要做的是添加此扩展,提供路径var(Networkmodel协议为API操作提供了一些基本功能):
extension Mymodels: Networkmodel { static var path = "the/endpoint/path" }
当base是对象或json键时,我在这种方式设置的其他模型/结构类中没有任何问题.但是,由于这个是不同的,并且只是一个数组,当我在该类中放入该扩展时,我收到此错误:
ConsTrained extension must be declared on the unspecialized generic type 'Array' with consTraints specified by a 'where' clause
我已经做了一些挖掘并尝试了一些关于扩展的where子句的东西,但我对它想要的东西感到有些困惑.我确定这很简单,但对此有何看法?如果我需要以不同的方式使用上面的类型,我很好.提前致谢!
以上是大佬教程为你收集整理的ios – Swift扩展 – 必须在非专用泛型类型’Array’上声明约束扩展全部内容,希望文章能够帮你解决ios – Swift扩展 – 必须在非专用泛型类型’Array’上声明约束扩展所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。