Custom UITextViewDelegate/UITextFieldDelegate not called
<p>Attempting to create custom delegate classes for <code>UITextViewDelegate</code> and <code>UITextFieldDelegate</code>. When I set these classes to be their own delegate, or set another UIKit component as their delegate, everything works fine. However, if I create my own class to serve as the delegate, the delegate methods are never called. Why?</p>

<p><strong>This works:</strong> </p>

<pre><code>class MyTextView: UITextView, UITextViewDelegate {
  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.delegate = self
}

func textViewDidChange(_ textView: UITextView) {
  print("I work")
}
</code></pre>

<p><strong>This does not:</strong></p>

<pre><code>class MyTextView: UITextView {
  required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.delegate = MyDelegate()
}

class MyDelegate: NSObject, UITextViewDelegate {
  func textViewDidChange(_ textView: UITextView) {
    print("I work")
  }
}
</code></pre>

<p><strong>Note:</strong> If <code>MyDelegate</code> does not subclass <code>NSObject</code>, the following error is thrown:</p>

<p><code>/// Type 'MyDelegate' does not conform to protocol 'NSObjectProtocol'</code></p>