小编Ken*_*dge的帖子

如何使泛型类符合特定类型的协议?

假设存在一个通用结构:

public struct Matrix<T> where T: FloatingPoint, T: ExpressibleByFloatLiteral {
// some methods...
}
Run Code Online (Sandbox Code Playgroud)

是否可以扩展struct以符合约束T使用where子句的协议?比如像

extension Matrix where T: SpecificClass : SomeProtocol {
    // This does not compile :(
}
Run Code Online (Sandbox Code Playgroud)

generics generic-programming swift swift-protocols swift4

5
推荐指数
1
解决办法
1795
查看次数