Swift泛型和相关类型出错

时间:2014-09-26 07:05:06

标签: generics swift associated-types

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

protocol Props {
    typealias ComponentType: Component<Self>
}

class Component<PropsType: Props> {
}

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

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

}

1 个答案:

答案 0 :(得分:2)

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

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

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

第二篇文章对你的问题非常有启发性。简单地说,swift没有协议的通用类型。希望这很有用。