Skip to content

Instantly share code, notes, and snippets.

@BeauNouvelle
Last active December 18, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BeauNouvelle/420638bec6eddd4bdf667a7678a20d9c to your computer and use it in GitHub Desktop.
Save BeauNouvelle/420638bec6eddd4bdf667a7678a20d9c to your computer and use it in GitHub Desktop.
class MockSession: URLSession {
var completionHandler: ((Data, URLResponse, Error) -> Void)?
static var mockResponse: (data: Data?, URLResponse: URLResponse?, error: Error?)
override class var shared: URLSession {
return MockSession()
}
override func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask {
self.completionHandler = completionHandler
return MockTask(response: MockSession.mockResponse, completionHandler: completionHandler)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment