Asynchronous Networking
DispatchQueue.global().async {
let data = Data(contentsOf: url)
DispatchQueue.main.async {
// Update UI
}
}
- There is no way to cancel this synchronous network call of Data
DispatchQueue.global().async {
let url = URL(string: "")!
let task = URLSession.shared.dataTask(with: url, completionHandler: { (data, response, error) in
DispatchQueue.main.async {
// Update UI
}
})
task.resume()
}