title: Swift: Why aren't my UITextFieldDelegate methods being called?
body: <p>I am trying to programmatically create a <code>UITextView</code> and create a delegate to handle the events. I am able to create add and the <code>UITextView</code> just fine, but none of the <code>UITextFieldDelegate</code> methods are bing added.
  Why would this be?</p>
  
  <pre><code>    let myTextField = UITextField()
      myTextField.frame = CGRect(x:0, y: 100, width: 300, height: 30)
      myTextField.text = "Example Text"
  
      class MyTextFieldDelegate : NSObject, UITextFieldDelegate {
          func textFieldShouldReturn(_ textField: UITextField) -&gt; Bool {
              // Hide the keyboard.
              print("should return!\n")
              textField.resignFirstResponder()
              return true
          }
  
          func textFieldDidEndEditing(_ textField: UITextField) {
              print("yay!\n")
              print(textField.text! + "\n")
          }
  
          func textFieldDidBeginEditing(_ textField: UITextField) {
              print("yay begin!\n")
              print(textField.text! + "\n")
          }
  
      }
  
      let myTextFieldDelegate = MyTextFieldDelegate()
      myTextField.delegate = myTextFieldDelegate
      scrollView.addSubview(myTextField)
  </code></pre>