Contents

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 : HKSample

Mentioned 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.

Topics

Creating Source Query Descriptors

Running Queries

Accessing Query Properties

Default Implementations

See Also

Sources and devices