Last active
July 1, 2020 10:05
-
-
Save archieedwards/3b45d87e1c50b85f8449e47224ab58d6 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 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