Реализация UITextFieldDelegate's
textField(_:shouldChangeCharactersIn:replacementString:)
метод, подобный так,
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if string.isEmpty {
textField.text?.removeLast()
return false
}
return true
}