Skip to content

Instantly share code, notes, and snippets.

@SebastianBoldt
Created January 31, 2022 08:04
Show Gist options
  • Save SebastianBoldt/925c30b804fd7b3391f7a270d6a734bb to your computer and use it in GitHub Desktop.
Save SebastianBoldt/925c30b804fd7b3391f7a270d6a734bb to your computer and use it in GitHub Desktop.
let loadDataTask = Task { () -> Data? in
let url = URL(string: "https://www.sebastianboldt.com")!
let (data, _) = try await URLSession.shared.data(from: url)
return data
}
let result = try await loadDataTask.result
switch result {
case let .success(data):
guard let string = String(data: data!, encoding: .utf8) else {
print("Could not create string")
return
}
print(string)
case let .failure(error):
print(error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment