-
-
Save laevandus/c0a65143933b9f451af60fe6f071b43f to your computer and use it in GitHub Desktop.
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
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