Powiedzmy, że mam te protokoły:
protocol SomeProtocol {
}
protocol SomeOtherProtocol {
}
Teraz, jeśli chcę funkcję, która przyjmuje typ ogólny, ale ten typ musi być zgodny z, SomeProtocolmogę zrobić:
func someFunc<T: SomeProtocol>(arg: T) {
// do stuff
}
Ale czy istnieje sposób na dodanie ograniczenia typu dla wielu protokołów?
func bothFunc<T: SomeProtocol | SomeOtherProtocol>(arg: T) {
}
Podobne rzeczy używają przecinków, ale w tym przypadku rozpoczęłoby to deklarację innego typu. Oto, czego próbowałem.
<T: SomeProtocol | SomeOtherProtocol>
<T: SomeProtocol , SomeOtherProtocol>
<T: SomeProtocol : SomeOtherProtocol>