Swift协议扩展中是否允许混合类/协议类型约束?

时间:2016-03-08 13:52:28

标签: swift swift-protocols protocol-extension

在任何版本的Swift中,是否有可能扩展具有混合类/协议类型约束的协议?例如,仅当Protocol2Self的子类并且符合UIViewController时,我才会延长Protocol1

protocol Protocol1 {}
protocol Protocol2 {}

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

1 个答案:

答案 0 :(得分:4)

尝试:

extension Protocol2 where Self: UIViewController, Self: Protocol2 {}