Queries
Query health and fitness data.
Overview
Use queries to read sample data from the HealthKit store. You can also use queries to list all the sources for a particular data type, or to perform statistical calculations for a data type. For example, statistical queries can calculate the minimum and maximum heart rate for a given week, or the total step count for a given day.
You run a query by calling the HealthKit store’s execute(_:) method. HealthKit returns a snapshot of the current results to the query’s results handler. Long-running queries continue to monitor the HealthKit store, and return any relevant changes to the query’s update handler. To return sorted or filtered results, give the query a sort descriptor or predicate.
Topics
Essentials
Swift concurrency support
Basic queries
Series queries
HKQuantitySeriesSampleQueryDescriptorHKQuantitySeriesSampleQueryHKWorkoutRouteQueryDescriptorHKWorkoutRouteQueryHKHeartbeatSeriesQueryDescriptorHKHeartbeatSeriesQueryHKElectrocardiogramQueryDescriptorHKElectrocardiogramQueryHKWorkoutEffortRelationshipHKWorkoutEffortRelationshipQuery
Long-running queries
HKActivitySummaryQueryDescriptorHKActivitySummaryQueryHKAnchoredObjectQueryDescriptorHKAnchoredObjectQueryHKObserverQuery
Sources and devices
Statistics
Executing Statistical QueriesExecuting Statistics Collection QueriesHKStatisticsQueryDescriptorHKStatisticsQueryHKStatisticsCollectionQueryDescriptorHKStatisticsCollectionQueryHKStatisticsHKStatisticsCollectionHKStatisticsOptions
Clinical record queries
HKVerifiableClinicalRecordQueryDescriptorHKVerifiableClinicalRecordQueryHKVerifiableClinicalRecordSourceTypeHKVerifiableClinicalRecordCredentialTypeHKDocumentQuery