I'm trying to use downloadTaskWithURL() but upgrading it to the latest version: downloadTask and I'm trying to run this code snippet but it won't compile.
Here's what I have done so far:
let downloadTask: URLSessionDownloadTask = URLSession.shared.downloadTask(with url: endpointURL, completionHandler: { (url: URL!, response: URLResponse!, error: Error!)
if (error == nil) {
//some code
}
})
downloadTask.resume()
What am I doing wrong?
You have several errors: your function signature is wrong (
urlis only used inside the function body, when calling it, the name of the input parameter iswith) and you missedinafter specifying the closure variables. Find the code which compiles without an issue below: