/UITestingNetworkHandler.swift Secret
Created
July 10, 2022 03:02
Star
You must be signed in to star a gist
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