Skip to content

Instantly share code, notes, and snippets.

@barisuyar
Created September 8, 2022 07:37
Show Gist options
  • Save barisuyar/aac4f8340a2218f785d4dbc982b91fde to your computer and use it in GitHub Desktop.
Save barisuyar/aac4f8340a2218f785d4dbc982b91fde to your computer and use it in GitHub Desktop.
override startLoading
final class MockURLProtocol: URLProtocol {
override class func canInit(with request: URLRequest) -> Bool {
true
}
override class func canonicalRequest(for request: URLRequest) -> URLRequest { request }
override func stopLoading() { }
override func startLoading() {
let jsonString = """
{
"name": "Barış Uyar",
"age": 29
}
"""
let jsonData = Data(jsonString.utf8)
client?.urlProtocol(self, didLoad: jsonData)
client?.urlProtocolDidFinishLoading(self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment