Skip to content

Instantly share code, notes, and snippets.

@karthikAdaptavant
Last active July 9, 2021 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikAdaptavant/79dffb9e23025205475fbba0c515d64d to your computer and use it in GitHub Desktop.
Save karthikAdaptavant/79dffb9e23025205475fbba0c515d64d to your computer and use it in GitHub Desktop.
enum Result<Value, Error: Swift.Error> {
case success(Value)
case failure(Error)
}
enum ApiError: Error {
case none
var desc: String {
return "this is desc"
}
}
func getSomethingFromServer(needValue: Bool) -> Result<Bool, ApiError> {
switch needValue {
case true:
return .success(true)
case false:
return .failure(ApiError.none)
}
}
let temp = getSomethingFromServer(needValue: true)
switch temp {
case .success(let value):
print("Success \(value)")
case .failure(let err):
print(err.desc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment