Sahil
Sahil

Reputation: 9226

Extend protocol to satisfy one of multiple constraints

I want to extend a protocol to satisfy one of multiple constraints. I know how to satisfy multiple constraints with (,), but that would conform to all of them.

Example:

protocol Abc { ... }
protocol xyz { ... }
protocol my  { ... }

extenstion  Abc where Self: xyz, Self: my {
...

}

I want Abc to either conform to xyz or my.

Upvotes: 5

Views: 320

Answers (1)

Lumialxk
Lumialxk

Reputation: 6369

I think you can use a common protocol to do this:

protocol Common {  }
protocol Abc {  }
protocol xyz: Common {  }
protocol my: Common  {  }

extension Abc where Self: Common {

}

Upvotes: 1

Related Questions