In Swift 2, I have a protocol:
protocol Protocol {
typealias Type
}
When I want to use Protocol
without defining what type to use for Type
:
var protocol1: Protocol
Then I'm getting the following error:
Protocol 'Protocol' can only be used as a generic constraint because it has Self or associated type requirements
It is clear why this is not going to work.
I have another protocol, which inherits from the first protocol and specifies that the associated type Type
should be a String
.
protocol AnotherProtocol: Protocol {
typealias Type = String
}
The same error occurs, when I try to use this protocol:
var protocol2: AnotherProtocol
Protocol 'AnotherProtocol' can only be used as a generic constraint because it has Self or associated type requirements
Why am I getting an error for this, although I have specified the associated type?
Is there another way for the second protocol to specify the associated type of the parent protocol, without having to specify it again in every class that implements the second protocol?