1

I have two generic classes which need each other to instantiate, is there an elegant way of doing that? Check out the following example:

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
}

As you can see, SomeViewController expecting the Presenter and the Presenter expecting the SomeViewController. So it's impossible to create one of them since we will have endless loop

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

Is there an elegant way of solving it?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
XcodeNOOB
  • 2,135
  • 4
  • 23
  • 29

0 Answers0