Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend protocol to satisfy one of multiple constraints

Tags:

swift

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.

like image 327
Sahil Avatar asked Nov 08 '22 17:11

Sahil


1 Answers

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 {

}
like image 195
Lumialxk Avatar answered Dec 24 '22 10:12

Lumialxk