Created
February 5, 2017 13:18
-
-
Save mkchoi212/69e988aefec50be3ddf774329e2e155f to your computer and use it in GitHub Desktop.
This file contains 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
// IMPLEMENTATION | |
enum LookupError: ErrorType { | |
case InvalidName | |
case NullData | |
} | |
enum UserResult { | |
case Success(String) | |
case Error(LookupError) | |
} | |
func findUserStatus(name: String) -> UserResult { | |
guard let userStats = users[name] else { | |
return .Error(InvalidName) | |
} | |
return .Success(userStats) | |
} | |
// USAGE | |
switch findUserStatus("Stevie Wonder") { | |
case let .Success(stats): | |
print("Stevie Wonder's Stats: \(stats)") | |
case let .Error(error): | |
print("Error: \(error)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment