Skip to content

Instantly share code, notes, and snippets.

@candostdagdeviren
Last active November 29, 2018 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candostdagdeviren/631aa7d7d83935f55e8a233d22803774 to your computer and use it in GitHub Desktop.
Save candostdagdeviren/631aa7d7d83935f55e8a233d22803774 to your computer and use it in GitHub Desktop.
Swift Post Concurrency Blog Post Code Example
let url = URL(string: "https://theswiftpost.co/")
if let url = url {
showLoadingIndicator() // UI Operation; has to run on the main queue
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
showErrorAlert(error) // UI operation; has to run on the main queue!!
} else if let data = data {
debugPrint(usableData) //JSONSerialization
}
debugPrint(“Completed”)
}
}
task.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment