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

后端 未结 4 1624
灰色年华
灰色年华 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:55

    Because of an issue in the previous answer I ended up with this declaration:

    protocol AddsMoreCommands where Self : UIViewController { 
        // protocol stuff here  
    }
    

    no warnings in Xcode 9.1

提交回复
热议问题