I have the first protocol
protocol Prot1
{
}
And the second:
protocol Prot2
{
associatedtype P: Prot1
func doSomething(param: P)
}
How can i make an array with the type Prot2?
I tried:
var myArray = [Prot2]()
But it gives me this error: Protocol Prot2 can only be used as a generic constraint because it has Self or associated type requirements
Is there any other way to make a template protocol?
EDIT:
Sorry if i am late, but i was testing the solutions. As far as i understand the type-erase
AnyProt2<Prot1Type: Prot1>: Prot2
let me have a an array with
[AnyProt2<Prot1Class>]
but i was asking for an array that could contain all kinds of AnyProt2 something like:
[AnyProt2] or [AnyProt2<Prot1>]
I tried the second but it gives me:
Using 'Prot1' as a concrete type conforming to protocol 'Prot1' is not supported.
In my context Prot1 is Interval and Prot2 is a Event, so i wanted to have and array with different kinds of Events that could have different kinds of Intervals. I also want to ask if it's possible to make Prot1 to extend Equatable and confirm the protocol in AnyProt2.