title: Swift 4 shouldChangeCharactersIn only show length = 12
body: <p>I have <code>textfield</code> ,<code>shouldChangeCharactersIn</code> codes im using barcode, system and my barcode codes == 12 characters. I want to show only 12 characters in my string if barcode small 12 characters or big must be return false or clean text field . my codes under below. When I using barcode if my barcodes 12 characters working fine , but if I read 12 character low don't clear textfield , </p>
  
  <blockquote>
    <p>How can I fix it ?</p>
  </blockquote>
  
  <p>My codes under below.</p>
  
  <pre><code> func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -&gt; Bool {
  
          let length = (Mytext.text?.characters.count)! - range.length + string.characters.count
          if length == 13 {
  
              print("Mytext=\(Mytext.text!)")
              Mytext.text = ""
  
              return true
  
          }else {
  
  
              return true
          }
  
  
      }
  </code></pre>
  
  <p>Output when read 12 characters barcode shows success !
  When read 12 characters low don't clear Mytext field , and when I read again adding +</p>