Skip to content

Instantly share code, notes, and snippets.

@novinfard
Last active March 4, 2019 23:25
Show Gist options
  • Save novinfard/e006e47820a2d3e48769ded9b6487399 to your computer and use it in GitHub Desktop.
Save novinfard/e006e47820a2d3e48769ded9b6487399 to your computer and use it in GitHub Desktop.
[Syncing multiple async tasks in Swift - code snippets 1]
func performNetworkRequest(url: String,
completion: @escaping (Data?, Error?) -> Void) {
// create a url
let requestUrl = URL(string: url)
// create a data task
let task = URLSession.shared.dataTask(with: requestUrl!) { (data, response, error) in
completion(data, error)
}
task.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment