简体   繁体   中英

Are mixed class/protocol type constraints allowed in Swift protocol extensions?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM