6

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

protocol Props {
    typealias ComponentType: Component<Self>
}

class Component<PropsType: Props> {
}

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

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

}
4

1 回答 1

2

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

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

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

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

于 2014-10-04T21:59:34.123 回答