【问题标题】:Are mixed class/protocol type constraints allowed in Swift protocol extensions?Swift 协议扩展中是否允许混合类/协议类型约束?
【发布时间】:2016-03-08 13:52:28
【问题描述】:

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

protocol Protocol1 {}
protocol Protocol2 {}

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

【问题讨论】:

    标签: swift swift-protocols protocol-extension


    【解决方案1】:

    试试:

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

    【讨论】:

      猜你喜欢
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-03
      • 2021-12-16
      相关资源
      最近更新 更多