Skip to content

Instantly share code, notes, and snippets.

@antonio081014
Created September 9, 2022 19:34
Show Gist options
  • Save antonio081014/dc04fa1440613fc824311e3f1ef6362f to your computer and use it in GitHub Desktop.
Save antonio081014/dc04fa1440613fc824311e3f1ef6362f to your computer and use it in GitHub Desktop.
class AsyncFileReading {
func asyncReadFile(_ url: URL) async throws -> Data {
let (data, _) = try await URLSession.shared.data(from: url)
return data
}
static func testout() {
let instance = AsyncFileReading()
let filename = "file_to_be_read.txt"
let url = Bundle.main.bundleURL.appending(component: filename)
Task {
let data = try await instance.asyncReadFile(url)
print(data.count)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment