Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Created June 13, 2021 07:02
Show Gist options
  • Save thanakijwanavit/e2b3a430317d78007af5711247a20433 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/e2b3a430317d78007af5711247a20433 to your computer and use it in GitHub Desktop.
swift async url call
do{
let url = URL(string: "htts://api.github.com/users/hadley/orgs")!
let (data, _) = try await URLSession.shared.data(from: url)
// decode json
let res = try JSONDecoder().decode([SampleJson].self, from: data)
// do stuff with result
// self.result = String(res.first!.id)
} catch {
print("error \(error)")
// send error to sentry sdk (optional)
SentrySDK.capture(error: error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment