_Posted this here, on Stackoverflow. But after 2+ weeks got only 10 views and no responses. _
I have my URLSession delegates working, but am curious about the order I get back response, data, and error.
Right now am testing purposeful errors on my server side, so I can check the response if it's not 200. If it's not, I do not need to process the data, etc.
So I could use a flag, but have to make sure that I'l always get response, data, and error in a specific order?
Does such an order exist?
extension UploadInv: UIDocumentPickerDelegate, URLSessionDataDelegate,URLSessionTaskDelegate, URLSessionDelegate {
// Error received
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let err = error {
print("Error: \(err.localizedDescription)")
}
}
// Response received
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: (URLSession.ResponseDisposition) -> Void) {
completionHandler(URLSession.ResponseDisposition.allow)
DispatchQueue.main.async { [self] in
if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode != 200 {
DispatchQueue.main.async { [self] in
self.myStatus.text = "Error \(String(httpResponse.statusCode))"
myBackButt.isEnabled = true
}
}
}
}
}
// Data received
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
DispatchQueue.main.async { [self] in