2

Swift のどのバージョンでも、クラス/プロトコル型の制約が混在するプロトコルを拡張することは可能ですか? たとえば、が のサブクラスであり、 に準拠しているProtocol2場合にのみ拡張したいと考えています。SelfUIViewControllerProtocol1

protocol Protocol1 {}
protocol Protocol2 {}

//What I imagine I could do, but it does not compile
extension Protocol2 where Self: UIViewController, Protocol2 {}
4

1 に答える 1

4

試す:

extension Protocol2 where Self: UIViewController, Self: Protocol2 {}
于 2016-03-08T14:15:43.200 に答える