title: Completely disable 'backspace' being pressed Swift
body: <p>I'm working on an app where the user needs to be able to type 'forwards' but is not able to delete anything (to go back and edit for example) that has already been typed.</p>
  
  <p>There are a few answers that are roughly what I want :</p>
  
  <p><a href="https://stackoverflow.com/questions/45730245/how-to-handle-backspace-in-uitextfield">how to handle backspace in uitextfield</a> - this is an old version of Swift i think as I got a lot of errors following this (deprecated, missing arguments etc). When trying this, I was thinking of doing something like the below :</p>
  
  <pre><code>func disableBackspace() {
  
  //do a check to see if the range of characters has reduced
  if range of characters in the string reduces (&lt;0?) {
  
  //if it has then don't allow the 'character' to be typed
  return false 
  }
  }
  </code></pre>
  
  <p>So I then liked the look of this method :</p>
  
  <p><a href="https://stackoverflow.com/questions/42642357/want-to-know-ever-time-while-pressing-on-keyboard-back-button-during-textfield-e">want to know ever time while pressing on keyboard back button during textfield editing ios</a></p>
  
  <p>So I tried :</p>
  
  <pre><code>func textView(_ textView: UITextView, shouldChangeCharactersIn range: NSRange, replacementString string: String) -&gt; Bool {
  
  //meant to detect if character was a backspace
  let char = string.cString(using: String.Encoding.utf8)
  let isBackSpace: Int = Int(strcmp(char, "\u{8}"))
  if isBackSpace == -8 {
      print("Backspace was pressed")
  }
  //meant to return false to not allow the backspace
          return false
  }
  </code></pre>
  
  <p>And have made my VC a textView delegate by doing </p>
  
  <pre><code>override func viewDidLoad() {
      self.textViewOutlet.delegate = self
  
      super.viewDidLoad()
  }
  </code></pre>
  
  <p>but that didn't work. It doesn't print anything and still allows the user to backspace. </p>
  
  <p>Any ideas much appreciated!</p>