Skip to content

Instantly share code, notes, and snippets.

@rbreve
Last active October 7, 2019 10:50
Show Gist options
  • Save rbreve/bc2eafe8e406e62ce9d36a6e9af3b2e6 to your computer and use it in GitHub Desktop.
Save rbreve/bc2eafe8e406e62ce9d36a6e9af3b2e6 to your computer and use it in GitHub Desktop.
public class MovieFetcher: ObservableObject {
@Published var movies = [Movie]()
init(){
load()
}
func load() {
let url = URL(string: "https://gist.githubusercontent.com/rbreve/60eb5f6fe49d5f019d0c39d71cb8388d/raw/f6bc27e3e637257e2f75c278520709dd20b1e089/movies.json")!
URLSession.shared.dataTask(with: url) {(data,response,error) in
do {
if let d = data {
let decodedLists = try JSONDecoder().decode([Movie].self, from: d)
DispatchQueue.main.async {
self.movies = decodedLists
}
}else {
print("No Data")
}
} catch {
print ("Error")
}
}.resume()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment