Created
September 8, 2022 07:37
-
-
Save barisuyar/aac4f8340a2218f785d4dbc982b91fde to your computer and use it in GitHub Desktop.
override startLoading
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
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