Let\'s say I have these protocols:
protocol SomeProtocol {
}
protocol SomeOtherProtocol {
}
Now, if I want a function that takes a gener
Swift 3 offers up to 3 different ways to declare your function.
protocol SomeProtocol {
/* ... */
}
protocol SomeOtherProtocol {
/* ... */
}
&
operatorfunc someFunc(arg: T) {
/* ... */
}
where
clausefunc someFunc(arg: T) where T: SomeProtocol, T: SomeOtherProtocol {
/* ... */
}
where
clause and &
operatorfunc someFunc(arg: T) where T: SomeProtocol & SomeOtherProtocol {
/* ... */
}
Also note that you can use typealias
in order to shorten your function declaration.
typealias RequiredProtocols = SomeProtocol & SomeOtherProtocol
func someFunc(arg: T) {
/* ... */
}