Created
July 26, 2019 07:53
-
-
Save wiiale/c60dfe0e4e13dd5c0c2a833b61c05146 to your computer and use it in GitHub Desktop.
Enumeration Nested Tip
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
import Foundation | |
struct Null {} | |
enum LikeError: Error { | |
case unknown | |
case liked | |
} | |
let likeResult: Result<Null, LikeError> = .failure(.liked) | |
// 1 | |
switch likeResult { | |
case .success: | |
print("Update") | |
print("...") | |
print("Lalala") | |
case .failure(let error): | |
switch error { | |
case .unknown: | |
print("Unknown error") | |
case .liked: | |
print("Update") | |
print("...") | |
print("Lalala") | |
} | |
} | |
// 2 | |
switch likeResult { | |
case .success, .failure(.liked): | |
print("Update") | |
print("...") | |
print("Lalala") | |
case .failure(.unknown): | |
print("Unknown error") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment