Skip to content

Instantly share code, notes, and snippets.

@navsing
Last active December 21, 2020 10:44
Show Gist options
  • Save navsing/005b851f4c95f2f9824800fb052f7b64 to your computer and use it in GitHub Desktop.
Save navsing/005b851f4c95f2f9824800fb052f7b64 to your computer and use it in GitHub Desktop.
func loadData() {
guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos") else {
print("Invalid URL")
return
}
let request = URLRequest(url: url)
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
if let response = try? JSONDecoder().decode([TaskEntry].self, from: data) {
DispatchQueue.main.async {
self.results = response
}
return
}
}
}.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment