swift - 条件协议(protocol)一致性?

标签 swift generics constraints protocols

我想做这样的事情:

class SomeClass<Element> { }
extension SomeClass: SomeProtocol where Element: String { }

它告诉我:

Extension of type "SomeClass" with constraints cannot have an inheritance clause.

到目前为止,我本可以发誓,这是协议(protocol)/扩展/通用/关联类型范式的基本功能之一。还有其他方法可以实现吗?

最佳答案

这是在 Swift 4.1 中实现的。

关于swift - 条件协议(protocol)一致性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359486/

相关文章:

java - 接口(interface)、泛型和重构

SQL 约束首字母大写

c++ - 使用 Gurobi 向模型添加约束时出现问题

swift - 在 SwiftUI 中动态更改和更新导航栏的颜色

ios - Swift - 在 SharkORM 中级联删除

swift - 如何使用 "OR"在 Swift 中比较字符串

ios - 截取当前未打开的 ViewController 的屏幕截图

java - 类型转换为嵌套在泛型类中的类

java - 在 Java 中使用类型转换和泛型

sql - 如何确保postgresql表中只有一列不为空