mirror of
https://github.com/mas-cli/mas
synced 2024-12-23 10:23:15 +00:00
26 lines
701 B
Swift
26 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)
|
||
|
}
|
||
|
}
|
||
|
}
|