title: UITextField - Get text before editing changed
body: <p>I set my text field to accept integer only but want to use UITextField inheritance rather than delegate of <code>shouldChangeCharactersInRange</code>.</p>
  
  <p>Is there any way to get text value before <code>editingChanged</code> called as using <code>dropLast()</code> won't work in case the typed-in character is not at the last position.</p>
  
  <pre><code>class TextFieldInteger: UITextField {
  
      // A character set with number digits only
      let decimalRange = CharacterSet.decimalDigits
  
      override func awakeFromNib() {
          self.addTarget(self, action: #selector(editingDidBegin), for: .editingDidBegin)
          self.addTarget(self, action: #selector(editingChanged), for: .editingChanged)
      }
  
      func editingDidBegin() {
          // Remove all existing "," from the input if having any
          input = input.replacingOccurrences(of: ",", with: "")
      }
  
      func editingChanged() {        
          if input.characters.count &gt; 0 {
              let textSet = CharacterSet(charactersIn: input)
              if !decimalRange.isSuperset(of: textSet) {
                  input.dropLast()
              }
          }
      }
  }
  
  extension UITextField {
      var input: String {
          get { return text ?? "" }
          set { text = newValue }
      }
  }
  </code></pre>