mirror of
https://github.com/mas-cli/mas
synced 2024-12-23 18:33:10 +00:00
aa0d204a07
https://www.swiftbysundell.com/posts/mocking-in-swift https://medium.com/@johnsundell/mocking-in-swift-56a913ee7484
25 lines
701 B
Swift
25 lines
701 B
Swift
//
|
|
// NetworkManager.swift
|
|
// MasKit
|
|
//
|
|
// Created by Ben Chatelain on 1/5/19.
|
|
// Copyright © 2019 mas-cli. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class NetworkManager {
|
|
private let session: NetworkSession
|
|
|
|
init(session: NetworkSession = URLSession.shared) {
|
|
self.session = session
|
|
}
|
|
|
|
func loadData(from url: URL, completionHandler: @escaping (NetworkResult) -> Void) {
|
|
session.loadData(from: url) { (data: Data?, error: Error?) in
|
|
let result: NetworkResult = data != nil ? .success(data!) : .failure(error!)
|
|
// let result = data.map(NetworkResult.success) ?? .failure(error)
|
|
completionHandler(result)
|
|
}
|
|
}
|
|
}
|