Skip to content

Instantly share code, notes, and snippets.

@danylokos
Created December 24, 2020 15:19
Show Gist options
  • Save danylokos/0f5498a3d0ee0034aa836017fe7d20c3 to your computer and use it in GitHub Desktop.
Save danylokos/0f5498a3d0ee0034aa836017fe7d20c3 to your computer and use it in GitHub Desktop.
swift multi protocol error
/*
compilation error:
Type 'StructC' does not conform to protocol 'ProtoA'
Type 'StructC' does not conform to protocol 'ProtoB'
*/
protocol ProtoAInput {
func funcA()
}
protocol ProtoA {
var input: ProtoAInput { get }
}
protocol ProtoBInput {
func funcB()
}
protocol ProtoB {
var input: ProtoBInput { get }
}
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment