Created
March 27, 2017 17:23
-
-
Save JohnSundell/63b1e4d23be82f088647f85ac93bb170 to your computer and use it in GitHub Desktop.
Code sample #2 from https://medium.com/@johnsundell/testing-swift-code-that-uses-system-singletons-in-3-easy-steps-89f4884cd325
This file contains 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
protocol NetworkEngine { | |
typealias Handler = (Data?, URLResponse?, Error?) -> Void | |
func performRequest(for url: URL, completionHandler: @escaping Handler) | |
} | |
extension URLSession: NetworkEngine { | |
typealias Handler = NetworkEngine.Handler | |
func performRequest(for url: URL, completionHandler: @escaping Handler) { | |
let task = dataTask(with: url, completionHandler: completionHandler) | |
task.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment