【发布时间】:2015-05-27 12:47:24
【问题描述】:
我正在尝试创建一个在 swift 中使用通用枚举的协议。
编译器抛出这个错误:Protocol can only be used as a generic constraint because it has associated type requirements
短代码被截断:
enum GenericEnum<T> {
case Unassociated
case Associated(T)
}
protocol AssociatedProtocol {
typealias AssociatedType
func foo() -> GenericEnum<AssociatedType>
}
let bar = [AssociatedProtocol]()
您可以找到更长的示例here。
有人知道这个问题的解决方案吗?
【问题讨论】:
-
AssociatedType的别名是什么?
标签: swift generics enums protocols