我有两个需要互相实例化的泛型类,是否有一种优雅的方式做到这一点? 请查看以下示例:
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>>> ...
是否有一种优雅的解决方法?