title: Can a class of UIView also be a UITextFieldDelegate?
body: <p>I am very new to Swift programming and am trying to understand why i can't make a custom UIView class also act as the delegate for TextFields. I have converted code that works with ViewController, but without much luck.
  The error is:
  <strong>fatal error: unexpectedly found nil while unwrapping an Optional value</strong>
  which is generated by the line :  textField.delegate = self </p>
  
  <p>Code as below:</p>
  
  <pre><code>import UIKit
  
  class ViewClass: UIView, UITextFieldDelegate {
  
  var textItems = [UITextInput]()
  var myKB = UIToolbar()
  var txtActive = 0
  
  @IBOutlet weak var textField: UITextField!
  
  required init?(coder decoder: NSCoder) {
      super.init(coder: decoder)
      textField.delegate = self
  }
  
  // UITextField Delegates
  func textFieldDidBeginEditing(textField: UITextField) {
      print("TextField did begin editing method called")
  }
  func textFieldDidEndEditing(textField: UITextField) {
      print("TextField did end editing method called")
  }
  func textFieldShouldBeginEditing(textField: UITextField) -&gt; Bool {
      print("TextField should begin editing method called")
      return true;
  }
  func textFieldShouldClear(textField: UITextField) -&gt; Bool {
      print("TextField should clear method called")
      return true;
  }
  func textFieldShouldEndEditing(textField: UITextField) -&gt; Bool {
      print("TextField should snd editing method called")
      return true;
  }
  func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -&gt; Bool {
      print("While entering the characters this method gets called")
      return true;
  }
  func textFieldShouldReturn(textField: UITextField) -&gt; Bool {
      print("TextField should return method called")
      textField.resignFirstResponder();
      return true;
  }
  }
  </code></pre>
  
  <p>Is this just impossible or am I missing/misunderstanding something basic??</p>