You can use where where , which allows you to specify as many requirements as you want (all this must be done), separated by commas
Swift 2:
func someFunc<T where T:SomeProtocol, T:SomeOtherProtocol>(arg: T) {
Swift 3 and 4:
func someFunc<T: SomeProtocol & SomeOtherProtocol>(arg: T) {
or a more powerful where clause:
func someFunc<T>(arg: T) where T:SomeProtocol, T:SomeOtherProtocol{
You can, of course, use the composition of the protocol (for example, protocol<SomeProtocol, SomeOtherProtocol> ), but it is slightly less flexible.
Using where allows you to handle cases where multiple types are involved.
You can still draw up protocols for reuse in several places, or just give the compiled protocol a meaningful name.
Jiaaro Jun 06 '14 at 19:27 2014-06-06 19:27
source share