Post

Replies

Boosts

Views

Activity

Reply to URLSessionDelegate usage
class ViewController: UIViewController {       var delegate: SessionHelper?       override func viewDidLoad() {     super.viewDidLoad()     // Do any additional setup after loading the view.         let request = URLRequest(url: URL(string: "https://www.google.com/")!)           let session = URLSession(configuration: .ephemeral, delegate: delegate, delegateQueue: nil)           session.dataTask(with: request) { data, response, error in       if let error = error {         print(error.localizedDescription)       } else {         // handle success request body                   if let _ = data {           print("success data got.")         }       }     }.resume()   }     } protocol SessionHelper: URLSessionDelegate {} extension SessionHelper {   func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {     print("challenge")   } } //class SessionHelper: NSObject, URLSessionDelegate { //  func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { // //    print("challenge") // //  } //}
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’21