How to require that a protocol can only be adopted by a specific class

后端 未结 4 1622
灰色年华
灰色年华 2021-02-01 00:13

I want this protocol:

protocol AddsMoreCommands {
     /* ... */
}

only to be adopted by classes that inherit from the class UIViewContro

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 00:34

    protocol AddsMoreCommands: class {
        // Code
    }
    
    extension AddsMoreCommands where Self: UIViewController {
        // Code
    }
    

提交回复
热议问题