Created
August 24, 2025 22:43
-
-
Save hmlongco/0cf68f3ec09a2a484aa2aaeba64fc299 to your computer and use it in GitHub Desktop.
Modern FetchData
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
func fetchData(url: String) async throws -> Data { | |
guard let requestURL = URL(string: url) else { | |
throw NetworkError.invalidURL | |
} | |
let (data, _) = try await URLSession.shared.data(from: requestURL) | |
guard !data.isEmpty else { | |
throw NetworkError.noData | |
} | |
return data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment