我正在尝试像这样利用泛型。
protocol Y { ... }
protocol X: Y { ... }
protocol A: Collection where Element == Y { ... }
protocol B: A where Element == X { ... }
我在以下定义中遇到错误B
:
同类型约束类型“X”不符合要求的协议“Y”
但是,X
确实符合Y
...
DataPoint
我尝试使用像这样的中间关联类型
protocol A: Collection where Element == DataPoint {
associatedtype DataPoint: Y
...
}
protocol B: A where DataPoint == X { ... }
但我得到同样的错误。是否有可能在 Swift 4 中完成这种事情,还是我必须制定两个完全独立的协议?