Error with Swift generics and associated types

The following Swift code causes compiler crashes. 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> { } 
+6
source share
1 answer

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

This second article sufficiently covers your problem. Simply put, swift does not have common protocol types. Hope this was helpful.

+2
source

Source: https://habr.com/ru/post/975869/


All Articles