swift - 如果 Self 是两个(或更多)类中的一个,是否允许使用协议?
问题描述
我正在做一个我希望 UIView 和 UIViewController 都可以使用的协议
我试着做
protocol ShowsResponse where Self: UIViewController, Self: UIView {
...
}
但正如错误所示,它解释为 Self 应该是 UIViewController 和 UIView
是否有类似“协议 ShowsResponse where Self: UIViewController”或“Self: UIView”
解决方案
Why don't you just try write down a protocol and write extension for UIViewController and UIView...
for example
extension UIView: ShowsResponse {
...
}
extension UIViewController: ShowsResponse {
...
}
protocol ShowsResponse {
...
}
I think this should solve your problem..
推荐阅读
- java - 在测试失败时,WebDriverEventListener 的方法“beforeGetScreenshotAs”会持续运行。这种方法的最佳实现是什么?
- deep-learning - 在 Google Colab 的 pytorch 下使 CUDA 内存不足
- ios - iOS SwiftUI:从父级到子级的 ObservableObject
- vb.net - DataGridView中的组合框如何填充第二列中的另一个组合框
- maven - “maven.compiler.release”作为源和目标的替代品?
- java - VisualVM 工具中的反向呼叫和前向呼叫
- sql - Oracle SQL 实时选择并连接数百万条记录的表
- javascript - 如何仅将 div 内容附加到类中一次?
- image-processing - 如何从 2D 点云或激光雷达扫描数据中检测角点?
- sql-server - 如何创建与 SQL Server 数据库的连接的连接池,确保所有连接保持打开状态