title: Swift - Calling a method in a UIViewController from a separate UIView class
body: <p>Okey, I have been struggling this for a long time now.. Cant get it to work, and I know there is an easy solution that I cannot find.</p>
  
  <p>I have a UIViewController displaying the main app. When it launches there is two containerViews overlaid that displays a count down for the app to start. Countdown is done, and the "overlay" viewcontrollers are removed from superview.</p>
  
  <p>BUT, I need to call the function to remove VC from superview and start the app in the main UIViewController. But I am not able to trigger this function from the separate "overlay" UIView.. </p>
  
  <p>If I make an instance of the UIViewController to trigger the startGame() function it works, but then all the labels return nil, and the app crashes.. I believe this is because the UIViewController is triggered twice? </p>
  
  <p>A lot of explaining here.. I will try to show some outtakes in code:</p>
  
  <p>Main UIViewController:</p>
  
  <pre><code>class DMStartVC: UIViewController {
  .....
  func startGame() {
      self.view.viewWithTag(100)?.removeFromSuperview()
      self.view.viewWithTag(101)?.removeFromSuperview()
      timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(DMStartVC.update), userInfo: nil, repeats: true)
      UITimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(DMStartVC.UIUpdate), userInfo: nil, repeats: true)
    }
  ....
  }
  </code></pre>
  
  <p>The UIView handling the "overlay" container views:</p>
  
  <pre><code>class countdown: UIView {
    let dmStartVC = DMStartVC()
    ...
    //when animation is done:
    dmStartVC.startGame()
  }
  </code></pre>
  
  <p>This causes crash because all labels in the UIViewController is nil.
  How can I reach that .startGame() function?</p>
  
  <p><em>Only way I have been able to solve this is adding a timer inside the DMStartVC to trigger .startGame()... But that is not a good solution as the timer has to trigger at the exact time the countdown ends.. and it never does.</em></p>