【发布时间】:2014-10-24 06:13:23
【问题描述】:
给定:
protocol MyProtocol {
typealias T
var abc: T { get }
}
还有一个实现 MyProtocol 的类:
class XYZ: MyProtocol {
typealias T = SomeObject
var abc: T { /* Implementation */ }
}
如何定义符合MyProtocol 的对象数组?
var list = [MyProtocol]()
给出(连同大量 SourceKit 崩溃)以下错误:
Protocol 'MyProtocol' can only be used as a generic constraint because it has Self or associated type requirements
尽管 typealias 实际上是在 MyProtocol 中定义的。
有没有办法让对象列表符合协议并具有通用约束?
【问题讨论】:
-
@Paulw11 糟糕,我完全错过了那个。
标签: ios cocoa-touch swift