Created
June 13, 2021 07:02
-
-
Save thanakijwanavit/e2b3a430317d78007af5711247a20433 to your computer and use it in GitHub Desktop.
swift async url call
This file contains hidden or 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
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