Created
August 11, 2018 18:42
-
-
Save vialyx/fc008d3db9f16fdcf4b416ec235a127d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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