I am trying to make an API call using dataTask
. I have a simple completion handler that, right now, is only used to test functionality. Even though I am using task.resume()
, the task does not seem to be executing as the print statement never appears on the console. Furthermore, when I put a breakpoint in the handler, the breakpoint is skipped.
let requestURL : URL = URL(string : baseURL + requestType)!
let currentURLRequest : URLRequest = URLRequest(url: requestURL)
var request : URLRequest = URLRequest(url: requestURL)
request.httpMethod = "GET"
let currentSession = URLSession.shared
var responseData : Data = Data()
let task = currentSession.dataTask(with: currentURLRequest, completionHandler: {
(data, response, error) in
responseData = data!
print("Closure has been called")
})
task.resume()
// responseData never gets reassigned, print statement never executes
If I am calling task.resume()
, why isn't the closure being called?