Here's my sample code. I'm trying to create a function builder that generates ContainerType
's with some unrelated-type input. In the sample code, I'm using a boolean (my actual code is parsing raw data).
protocol ProtocolType {
}
struct ConformingA: ProtocolType {
}
struct ConformingB: ProtocolType {
}
struct ContainerType<E> where E: ProtocolType {
let contents: E
init(contents: E) {
self.contents = contents
}
}
func make(from bool: Bool) -> ContainerType<???> {
if bool {
return ContainerType(contents: ConformingA())
} else {
return ContainerType(contents: ConformingB())
}
}
Where I've put the ???
is the point where it stops working. If I write any ProtocolType
(which is my interpretation of what I need) I get the following error:
Type 'any ProtocolType' cannot conform to 'ProtocolType'