Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created July 10, 2022 03:02
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 laevandus/c0a65143933b9f451af60fe6f071b43f to your computer and use it in GitHub Desktop.
Save laevandus/c0a65143933b9f451af60fe6f071b43f to your computer and use it in GitHub Desktop.
public final class UITestingNetworkHandler {
public static func register() {
URLProtocol.registerClass(UITestingURLProcotol.self)
UITestingURLProcotol.responseProvider = { request in
guard let url = request.url else { fatalError() }
switch (url.host, url.path) {
case ("augmentedcode.io", "/api/example"):
let response = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil)!
let data = "MyMockedData".data(using: .utf8)!
return .success(UITestingURLProcotol.ResponseData(response: response, data: data))
default:
fatalError("Unhandled")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment