Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NetworkManager {
- // Stores the session used in this class
- private let session: URLSession
- // Dependency Injection + default argument for normal initializ
- init(session: URLSession = .shared) {
- self.session = session
- }
- func loadData(from url: URL,
- completionHandler: @escaping (NetworkResult) -> Void) {
- let task = session.dataTask(with: url) { data, _, error in
- let result = data.map(NetworkResult.success) ?? .failure(error)
- completionHandler(result)
- }
- task.resume()
- }
- }
Add Comment
Please, Sign In to add comment