title: How to partially mask a UITextField text in swift?
body: <p><code>--------------------</code><br>
  <code>|</code> **** **** **** 1234  <code>|</code><br>
  <code>--------------------</code></p>
  
  <p>As you can tell, I'm trying to partially mask the first 12 digits of a card number which the user types in a <code>UITextField</code>. It took me a lot of time to figure out how to separate the digits in chunks of 4. Now the challenge I'm taking up is to mask the first 12 digits with secure-entry style mask.</p>
  
  <p>Any help would be greatly appreciated. Thank you.</p>
  
  <p>Edit:<br>
  Adding code that I have tried so far:</p>
  
  <pre><code>func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -&gt; Bool {
      guard let text = textField.text else {
          return true
      }
      //@"●"
      let lastText = (text as NSString).replacingCharacters(in: range, with: string) as String
      if txtCardNumber.text?.characters.count &gt;= 12 {
          txtCardNumber.text = "●●●● ●●●● ●●●●" // + String()
          return true
      }
      return true
  }
  </code></pre>
  
  <p>Objective:  I have posted what I attempted. Not able to get past the point of using the ● 12 times after determining the length of the textField is more than 12. Stuck here. To answer your question, it needs to show the number when typed but replace with ● when the next number is type. Continue same behavior till length is 12 and then show numbers from there on till 16th digit.</p>