title: Detect when UITextField is changed not using the keyboard swift
body: <p>I would like to know when the "text" property of myTextField, which is a subclass of UITextField, is cleared by my app. Since I have many textFields in my app I would like it to be a mechanism from within the subclass.</p>
  
  <p>I found posts that suggest to use observer, and I tried it and it works but I would like a better way.</p>
  
  <p>The problem with this method is that when I enter a single character using the keyboard and then I clear the "Text" from my app using </p>
  
  <pre><code>someField.text = ""
  </code></pre>
  
  <p>the observer calls my app 50 times, which is very inefficient.</p>
  
  <p>Here is the code I use in myTextField class:</p>
  
  <pre><code>addObserver(self, forKeyPath: "text", options: .New, context: nil)
  </code></pre>
  
  <p>and the function that gets the message is</p>
  
  <pre><code>override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer&lt;Void&gt;) {
      if let newValue = change?[NSKeyValueChangeNewKey] {
          print("text changed: \(newValue)")
      }
  }
  </code></pre>
  
  <p>The print() is called more than 50 times with "newValue" being empty ech time.
  Also, other textFields that has no data in their "text" property get called 5 times when I set their "text" property to "" from within my app, which is also inefficient.</p>