Skip to content

Instantly share code, notes, and snippets.

@wiiale
Created July 26, 2019 07:53
Show Gist options
  • Save wiiale/c60dfe0e4e13dd5c0c2a833b61c05146 to your computer and use it in GitHub Desktop.
Save wiiale/c60dfe0e4e13dd5c0c2a833b61c05146 to your computer and use it in GitHub Desktop.
Enumeration Nested Tip
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