Last active
December 21, 2020 10:44
-
-
Save navsing/005b851f4c95f2f9824800fb052f7b64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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