Created
July 1, 2020 09:50
-
-
Save archieedwards/80100071d516d79948f6ed22e121fb6e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public final class NetworkClient { | |
private let n: NetworkClientProtocol | |
init(n: NetworkClientProtocol = URLSession.shared) { | |
self.n = n | |
} | |
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) { | |
n.executeRequest(request: request){ (data, error) in | |
if let error = error { | |
completion(.failure(error)) | |
return | |
} | |
guard let data = data else { | |
completion(.failure(NetworkError.noData)) | |
return | |
} | |
completion(.success(data)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment