title: iOS 12: How to add UIView to UIViewController programatically?
body: <p>I use old way to inject <code>UIView</code> to <code>UIViewController</code>, but after upgrade to iOS 12, it won't work and the error is:
  <code>libc++abi.dylib: terminating with uncaught exception of type NSException</code></p>
  
  <p>Here is the code</p>
  
  <pre><code>class SlideOutMenu: UIViewController {
      var contentView:UIView!
  
      func setContentViewIn(view: UIView) {
          self.contentView = view
          self.view.addSubview(self.contentView)
      }
  }
  </code></pre>
  
  <p>Then </p>
  
  <pre><code>class MainController: UIViewController {
      var slide = SlideOutMenu()
      var viewToAdd = ViewToAdd() // extends UIView
      override func viewDidLoad()
      {
          super.viewDidLoad()
          slide.setContentViewIn(viewToAdd)
      }
  }
  </code></pre>
  
  <p>It doesn't work, but if i declare like this, it works</p>
  
  <pre><code>class SlideOutMenu: UIViewController {
      var contentView:UIView!
      convenience init(childView: UIView) {
          self.init(nibName:nil, bundle:nil)
          self.contentView = childView
      }
  
      override func viewDidLoad() {
          view.addSubview(self.contentView)
      }
  }
  </code></pre>
  
  <p>And use</p>
  
  <pre><code>SlideOutMenu(childView: UIView())
  </code></pre>
  
  <p>It works.</p>
  
  <p>But like this, it doesn't. That is weird</p>
  
  <pre><code>SlideOutMenu(childView: viewToAdd)
  </code></pre>