Skip to content

Instantly share code, notes, and snippets.

@michaelevensen
Created October 14, 2022 12:00
Show Gist options
  • Save michaelevensen/d648ad1d89e87b17fc0b99f774554ae8 to your computer and use it in GitHub Desktop.
Save michaelevensen/d648ad1d89e87b17fc0b99f774554ae8 to your computer and use it in GitHub Desktop.
func fetchData() async
throws {
guard let url = URL(string: urlString) else { return }
let (data, response) = try await URLSession.shared.data(for: URLRequest(url: url))
guard (response as? HTTPURLResponse)?.statusCode == 200 else { throw FetchError.badRequest }
Task { @MainActor in
imageData = try JSONDecoder().decode(PandaCollection.self, from: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment