swift - 如何实例化两个相互依赖的泛型类?
问题描述
我有两个需要彼此实例化的通用类,有没有一种优雅的方法呢?查看以下示例:
protocol Presentable {
/// Protocol for view
}
protocol Action {
/// Protocol for Presenter
}
class Presenter<T: Presentable> : Action {
/// Presenter looking for a class that implementing the Presentable protocol
}
class SomeViewController<T: Action> : Presentable {
/// SomeViewController looking for a class that implementing the Action protocol
}
如您所见,SomeViewController
期待Presenter
和Presenter
期待SomeViewController
。所以不可能创建其中之一,因为我们将有无限循环
let vc = SomeViewController<Presenter<SomeViewController<Presenter>>> ...
有没有优雅的解决方法?
解决方案
推荐阅读
- javascript - 停止滚动页面但仍接收垂直滚动值?
- django - Django 'title_en' 不在列表中
- .net-core - 将 emailsettings 从 web.config 转换为 appsettings.json
- html - 如何通过叠加响应使方形裁剪图像响应
- r - R 在安装 ChemmineR 时挂起
- javascript - VueJS Bulma Sweet 模式总是在 For 循环内切换到页面顶部
- rust - 如果它们包含空格,如何从构建脚本将标志传递给 rustc?
- java - 读/写锁的条件
- javascript - cursor.update(val) OR put(val, id)?
- java - 如何用父节点包装 XML 数组类型节点