Swift泛型和相关类型出错

igu*_*222 6 generics associated-types swift

以下Swift代码反复崩溃编译器.我错过了什么?

protocol Props {
    typealias ComponentType: Component<Self>
}

class Component<PropsType: Props> {
}

class FooProps : Props {
    typealias ComponentType = FooComponent<FooProps>
}

class FooComponent<PropsType: Props> : Component<PropsType> {

}
Run Code Online (Sandbox Code Playgroud)

Ste*_*erg 2

关于协议中泛型的使用已经有一些很好的讨论。

http://schani.wordpress.com/2014/06/03/playing-with-swift/

http://schani.wordpress.com/2014/06/11/linked-types-considered-weird

第二篇文章对你的问题很有启发。简而言之,Swift 没有协议的泛型类型。希望这有用。