I have a quick protocol containing one property:
protocol WireframeProtocol: class { var rootViewController: UIViewController { get } }
Then I have a class that implements this protocol as such:
class MenuWireframe : WireframeProtocol { let rootViewController: UIViewController init() { self.rootViewController = MenuViewController(nibName: "MenuViewController", bundle: nil) (self.rootViewController as! MenuViewController).presenter = MenuPresenter(interactor: MenuInteractor()) } }
In my Wireframe class, the variable is actually of type MenuViewController, but should instead be declared as a UIViewController to confirm the protocol. I have to use (self.rootViewController as! MenuViewController) to downgrade it to the class I want to have access to its properties. This is good in my simple example above, but not very readable, especially in more complex situations. Is there a better way to declare a protocol variable?
Thank you very much!
source share