I have UITextField
and i want allow user to type only up to 4 symbols. But i also want to allow them to erase symbols with keyboard (i mean, delete last and move caret for left. Symbol look like rectangle left arrow with cross on iOS keyboard).
For now i ended up with:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text, text.count < 4 else { return false }
return true
}
But i have no idea, how to let users to delete symbols. When text count become 4, i am not allowed to type or do any actions.