2016-03-08 90 views
2

是否可以在任何版本的Swift中扩展具有混合类/协议类型约束的协议?例如,仅当SelfUIViewController的子类并且符合Protocol1时,我想扩展Protocol2Swift协议扩展中允许混合类/协议类型约束吗?

protocol Protocol1 {} 
protocol Protocol2 {} 

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

回答

4

尝试:

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