HKSourceQueryDescriptor
A query interface that uses Swift concurrency to read the apps and devices that produced the matching samples.
Declaration
struct HKSourceQueryDescriptor<Sample> where Sample : HKSampleMentioned in
Overview
Use HKSourceQueryDescriptor to run a general query that returns a snapshot of all the apps and devices that have saved matching data to the HealthKit store.
// Create the source descriptor.
let sourceDescriptor = HKSourceQueryDescriptor(predicate: .workout())
// Read the source data from the HealthKit store.
let sources = try await sourceDescriptor.result(for: store)
for source in sources {
// Process the sources here.
print(source)
}When you call the descriptor’s result(for:) method, it creates and executes an HKSourceQuery in the background, passing the results as an array of HKSource instances.