HKAttachment.AsyncBytes
An asynchronous sequence that returns the attached file as a series of bytes.
Declaration
struct AsyncBytesOverview
To access the attachment file as an asynchronous sequence of bytes, get a data reader from the attachment store, and then access its bytes using a for-await-in loop.
// Get a data reader for the attachment.
let dataReader = attachmentStore.dataReader(for: myAttachment)
// Asynchronously access the attachment's bytes.
var data = Data()
do {
for try await byte in dataReader.bytes {
data.append(byte)
}
} catch {
// Handle the error here.
fatalError("*** An error occurred while reading the attachment's data: \(error.localizedDescription) ***")
}
// Use the data here.