Skip to content

Instantly share code, notes, and snippets.

@archieedwards
Last active July 1, 2020 10:05
Show Gist options
  • Save archieedwards/3b45d87e1c50b85f8449e47224ab58d6 to your computer and use it in GitHub Desktop.
Save archieedwards/3b45d87e1c50b85f8449e47224ab58d6 to your computer and use it in GitHub Desktop.
public final class NetworkClient {
private let session: URLSession = .shared
public init() { }
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) {
session.dataTask(with: 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))
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment