Is it possible, in any version of Swift, to extend a protocol with mixed class/protocol type constraints? For example, I would like to extend Protocol2
only when Self
is a subclass of UIViewController
and conforms to Protocol1
.
protocol Protocol1 {}
protocol Protocol2 {}
//What I imagine I could do, but it does not compile
extension Protocol2 where Self: UIViewController, Protocol2 {}
尝试:
extension Protocol2 where Self: UIViewController, Self: Protocol2 {}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.