Created
January 31, 2022 08:04
-
-
Save SebastianBoldt/925c30b804fd7b3391f7a270d6a734bb to your computer and use it in GitHub Desktop.
This file contains 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
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