Skip to content

Instantly share code, notes, and snippets.

Created February 23, 2021 23:00
What would you like to do?
This abstraction contains either a success data of generic type `T` or an error of type `ErrorCode` as its result.
enum ErrorCode: Equatable, Error {
case unknown
// Top level server error
case serverIssue
// Network
case noNetworkConnection
enum DataResult<T> {
case success(value: T)
case error(ErrorCode)
var value: T? {
switch self {
case .success(value: let value):
return value
case .error:
return nil
var error: ErrorCode? {
switch self {
case .success:
return nil
case let .error(error):
return error
extension DataResult: Equatable where T: Equatable {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment