title: Is it OK to have fatalError in required init?(coder aDecoder: NSCoder) when I don't use Storyboards?
body: <p>I have a <code>ViewController</code>, which need to be initialized with <code>ViewModel: NSObject</code>.</p>
  
  <p>My implementation of <code>ViewController</code> is:</p>
  
  <pre><code>class ViewController: UIViewController {
  
      let viewModel: ViewModel
  
      init(withViewModel viewModel: ViewModel) {
          self.viewModel = viewModel
          super.init(nibName: nil, bundle: nil)
      }
  
      required init?(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
  }
  </code></pre>
  
  <p><code>ViewModel</code> has simple <code>override init</code>:</p>
  
  <pre><code>class ViewModel: NSObject {
  
      override init() {
          super.init()
          // Some other logic
      }
  
  }
  </code></pre>
  
  <p>I understand, that I need <code>required init?(coder aDecoder: NSCoder)</code> in <code>ViewController</code> implementation since it conforms <code>NSCoding</code> protocol. But I'm not sure if it is safe to have <code>fatalError</code> there.</p>
  
  <p>When I change <code>fatalError</code> to <code>super.init(coder: aDecoder)</code> I receive</p>
  
  <blockquote>
    <p>property 'self.viewModel' not initialized at super.init call</p>
  </blockquote>
  
  <p>I don't want to make <code>viewModel</code> an optional variable, because in my App logic it can't be <code>nil</code>.</p>
  
  <p>Also, when I change <code>init?(coder...</code> to</p>
  
  <pre><code>required init?(coder aDecoder: NSCoder) {
      self.viewModel = ViewModel()
      super.init(coder: aDecoder)
  }
  </code></pre>
  
  <p>this also doesn't satisfy me, since <code>viewModel</code> isn't the only constant, which need to be implemented during initialization of <code>ViewController</code>.</p>
  
  <p>So, my questions: </p>
  
  <ul>
  <li>Is it safe to have <code>fatalError</code> in this <code>init</code> method?</li>
  <li>I <strong>don't use Storyboards</strong> in my App (only for Launch Screen). Can I be sure, that this <code>init?(coder...</code> method won't run in any case?</li>
  <li>Or maybe there is an option to write it without <code>fatalError</code>?</li>
  <li>Or do I need a full implementation in it, because in some cases my App will use it?</li>
  </ul>
  
  <p>Thanks for any help!</p>