我想要这个协议(protocol):
protocol AddsMoreCommands {
/* ... */
}
仅被继承自 UIViewController
类的类采用。 This page告诉我我可以指定它只被一个类(而不是一个结构)通过编写来采用
protocol AddsMoreCommands: class {
}
但我看不出如何要求它只被特定的类采用。 That page later谈论将 where
子句添加到协议(protocol)扩展以检查一致性,但我也看不出如何调整它。
extension AddsMoreCommands where /* what */ {
}
有没有办法做到这一点? 谢谢!
最佳答案
protocol AddsMoreCommands: class {
// Code
}
extension AddsMoreCommands where Self: UIViewController {
// Code
}
关于swift - 如何要求一个协议(protocol)只能被特定的类采用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35133887/