Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with Swift generics and associated types

The following Swift code repeatedly crashes the compiler. What am I missing?

protocol Props {
    typealias ComponentType: Component<Self>
}

class Component<PropsType: Props> {
}

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

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

}
like image 278
igul222 Avatar asked Sep 26 '14 07:09

igul222


1 Answers

There have been some good discussions on the use of generics in protocols.

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

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

That second article is quite illuminating for your issue. Simply put, swift doesn't have generic types for protocols. Hope this was useful.

like image 194
Steve Rosenberg Avatar answered Sep 22 '22 05:09

Steve Rosenberg