I have the next protocols:
protocol ProtoAInput {
func funcA()
}
protocol ProtoA {
var input: ProtoAInput { get }
}
protocol ProtoBInput {
func funcB()
}
protocol ProtoB {
var input: ProtoBInput { get }
}
I want to have my StructC to conform to both protocols ProtoA and ProtoB, with just a single input property. Which itself is just a reference to self, as StructC also implements ProtoAInput and ProtoBInput in a separate extension.
struct StructC: ProtoA, ProtoB {
var input: ProtoAInput & ProtoBInput { return self }
}
extension StructC: ProtoAInput {
func funcA() { print("funcA") }
}
extension StructC: ProtoBInput {
func funcB() { print("funcB") }
}
let s = StructC()
s.funcA()
s.funcB()
Swift 5.3 compiler fails to build this code with the following errors:
Type 'StructC' does not conform to protocol 'ProtoA'
Type 'StructC' does not conform to protocol 'ProtoB'
Are there any compilation rules that this code violates? I don't understand why I can't have input variable that simultaneously conforms to both protocols here.
