swift - 为什么不能符合关联类型的协议?
问题描述
我有以下简单的协议:
protocol JSONParser {
associatedtype JSONResult
func parse<T: Codable>(response: Response, type: T) -> JSONResult
}
函数parse
采用 simple Response
which is struct 并采用T
which is Codable
。以下是我实现此协议的方式:
struct AuthJSONParser: JSONParser {
func parse<T: Codable>(response: Response, type: T) -> AuthResult<T> {
}
}
似乎一切都好。但是 Xcode 说它不符合协议。这里AuthResult<T>
只是为了案例:
enum AuthResult<Model: Codable> {
case success(data: Model)
case failed(msg: String)
}
我无法弄清楚我的实施有什么问题。我想使用泛型函数,而不是泛型结构。
解决方案
推荐阅读
- javascript - 根据 props 改变 react 组件的样式
- python-3.x - PyQt5 - 使用取消按钮关闭 QDialog 窗口
- android - 禁用 JNI C 代码中变量的编译器优化
- c - 带有指针的结构更改值而不重新分配
- java - spring batch 3600个分区在启动前长时间停顿
- ios - 找不到 -lGoogleToolboxForMac 的代码管道库
- swift - 百分比完成计算器 swift
- clojure - 创建连接 Threadpoolbudget 的 Datomic 错误
- java - WindowAdapter 和 WindowDestroyer 的 Java 错误
- javascript - 在 vue.js 中的数组中的项目渲染转换之间进行延迟