1

我有两个需要彼此实例化的通用类,有没有一种优雅的方法呢?查看以下示例:

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期待PresenterPresenter期待SomeViewController。所以不可能创建其中之一,因为我们将有无限循环

let vc = SomeViewController<Presenter<SomeViewController<Presenter>>> ...

有没有优雅的解决方法?

4

0 回答 0