Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created August 11, 2018 18:42
Show Gist options
  • Save vialyx/fc008d3db9f16fdcf4b416ec235a127d to your computer and use it in GitHub Desktop.
Save vialyx/fc008d3db9f16fdcf4b416ec235a127d to your computer and use it in GitHub Desktop.
enum EmailValidationError {
// TODO: - Cases
case empty
// TODO: - Cases can be declared on a single line
case noDomain(String)
case invalid(String)
}
// TODO: - Create a new error
var error = EmailValidationError.empty
// TODO: - OR type-inferred
var signupError: EmailValidationError = .invalid("maxxxxxxx.com")
error = .noDomain("max@")
// MARK: - Matching
switch error {
case .empty:
print("Please provide email")
case .noDomain(let email):
print("Add domain: \(email)")
case .invalid(let email):
print("Entered email looks like invaid: \(email)")
}
if case let .invalid(email) = signupError {
print("Entered email looks like invaid: \(email)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment