getAttachments(for:completion:)
Returns all the attachments for the specified object.
Declaration
func getAttachments(for object: HKObject, completion: @escaping @Sendable ([HKAttachment]?, (any Error)?) -> Void)func attachments(for object: HKObject) async throws -> [HKAttachment]Parameters
- object:
An object from the HealthKit store.
- completion:
A completion handler that the system calls to return the attachment. This handler takes the following parameters:
- attachments
An array of attachments. If an error occurs, the system sets this parameter to
nil.- error
If an error occurred, this parameter contains information about the error. Otherwise, it’s
nil.
Discussion
Call this method to get all the attachments for the specified object.
let attachments: [HKAttachment]
do {
attachments = try await attachmentStore.attachments(for: prescription)
} catch {
// Handle the error here.
fatalError("*** An error occurred while accessing the attachments for a prescription: \(error.localizedDescription) ***")
}
// Use the attachments here.