MaterialTextField
MaterialTextField copied to clipboard
how to show an error in MaterialTextFiel?.
I am not able to show an error. Could you please provide me an example.
Here's my suggestion :
Start by defining your own error type like :
enum TextFieldError: Error {
case emptyTextField
}
extension TextFieldError: LocalizedError {
public var errorDescription: String? {
switch self {
case .emptyTextField:
return "Here, the string you want to display below the text field"
}
}
}
Then, you can use later it as :
if titleTextField.text == "" {
let error: Error = TextFieldError.emptyTextField
titleTextField.setError(error, animated: true)
}
Hope it will help
how to turn off error state