Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created August 11, 2018 18:53
Show Gist options
  • Save vialyx/148ee245f4694518df4da2ef956fd793 to your computer and use it in GitHub Desktop.
Save vialyx/148ee245f4694518df4da2ef956fd793 to your computer and use it in GitHub Desktop.
enum EmailValidationError: Error {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain(String)
case invalid(String)
}
extension EmailValidationError: LocalizedError {
var errorDescription: String? {
switch self {
case .invalid:
return "This email is incorrect. Please, try again"
case .empty:
return "This email is empty. Please, fill it"
case .noDomain:
return "This email without domain. Please, try again"
}
}
}
let error = EmailValidationError.empty
print("error: \(error.localizedDescription)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment