Created
May 6, 2019 08:56
-
-
Save giln/b66647a113837d53ddd7a167563e4ec6 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
import Foundation | |
public protocol DataFetching { | |
func fetchData(url: URL, completion: @escaping (Data?, Error?) -> Void) | |
} | |
extension DataFetching { | |
public func fetchData(url: URL, completion: @escaping (Data?, Error?) -> Void) { | |
let session = URLSession.shared | |
session.dataTask(with: url) { (data, response, error) in | |
completion(data, error) | |
}.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment