igul222
igul222

Reputation: 8637

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> {

}

Upvotes: 6

Views: 228

Answers (1)

Steve Rosenberg
Steve Rosenberg

Reputation: 19524

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.

Upvotes: 2

Related Questions