Last active
July 9, 2021 14:27
-
-
Save karthiikmk/79dffb9e23025205475fbba0c515d64d 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
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