Skip to content

Instantly share code, notes, and snippets.

@archieedwards
Created July 1, 2020 09:50
Show Gist options
  • Save archieedwards/80100071d516d79948f6ed22e121fb6e to your computer and use it in GitHub Desktop.
Save archieedwards/80100071d516d79948f6ed22e121fb6e to your computer and use it in GitHub Desktop.
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