Contents

result(for:)

Runs a one-shot query and asynchronously returns a snapshot of the current matching results.

Declaration

func result(for healthStore: HKHealthStore) async throws -> Self.Output

Parameters

  • healthStore:

    The access point for HealthKit data.

Mentioned in

Discussion

The adopting type’s Output associated type specifies the values that this method returns. For example, HKSampleQueryDescriptor returns an array of HKQuantitySample objects.

let stepType = HKQuantityType(.stepCount)

let descriptor = HKSampleQueryDescriptor(
    predicates:[.quantitySample(type: stepType)],
    sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
    limit: 10)

let results = try await descriptor.result(for: store)

See Also

Running Queries