Skip to content

Instantly share code, notes, and snippets.

@backslash-f
Created January 23, 2022 19:54
Show Gist options
  • Save backslash-f/66c9bdd40e7dc56d7d376299df3dc7c9 to your computer and use it in GitHub Desktop.
Save backslash-f/66c9bdd40e7dc56d7d376299df3dc7c9 to your computer and use it in GitHub Desktop.
Charles + Swift Playgrounds
// "Charles Enabler"
// https://stackoverflow.com/a/57253011/584548
public class NetworkEnabler: NSObject, URLSessionDelegate {
public func urlSession(_ session: URLSession,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}
// Then, when creating a URLSession instance:
let urlSession = URLSession(configuration: .default, delegate: NetworkEnabler(), delegateQueue: nil)
// Create a request and finally...
let (data, response) = try await urlSession.data(for: request)
// Profit 💰
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment