title: How to unit test `viewDidLoad()`
body: <p>What is everybody's favourite way of injecting dependencies when unit testing <code>UIViewController.viewDidLoad()</code> method on iOS?</p>
  
  <p>Given my implementation is:</p>
  
  <pre><code>class MyViewController: UIViewController {
  
      var service: Service = Service()
  
      override func viewDidLoad() {
          super.viewDidLoad()
          service.load()
      }
  }
  </code></pre>
  
  <p>And my test class is something along this:</p>
  
  <pre><code>class MyViewController Tests: XCTestCase {
  
       var vc: MyViewController!
       var serviceMock = ServiceMock()
  
      override func setUp() {
         super.setUp()
         let storyboard = UIStoryboard(name: "Main", bundle: nil)
         vc = storyboard.instantiateViewController(withIdentifier: "MyViewController") as! MyViewController
         vc.service = serviceMock
      }
  }
  
  func testThatServiceIsCalled() {
  
         XCTAssertTrue(serviceMock.loadCalled)
   }
  </code></pre>
  
  <p>The obvious problem here is that <code>viewDidLoad()</code> is called at the moment I instantiate the viewController and the test fails as the mock is not injected properly.</p>
  
  <p>Any solution?</p>