---
title: HKQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hkquery
---

# HKQuery

An abstract class for all the query classes in HealthKit.

## Declaration

```swift
class HKQuery
```

## Mentioned in

Dividing a HealthKit workout into activities

## Overview

Overview The HKQuery class is the basis for all the query objects that retrieve data from the HealthKit store. The HKQuery class is an abstract class. You should never instantiate it directly. Instead, you always work with one of its concrete subclasses. Filter queries using predicates All the concrete HKQuery subclasses take a predicate. You can use this predicate to filter the samples returned by the query. When HealthKit runs a query, it converts the predicate to SQL and executes the SQL on the underlying store. This has two important side effects. Predicates improve the performance of your query, both in terms of speed and memory usage. Because the store executes the predicate, it restricts the number of HealthKit objects that it instantiates and returns. Since the store executes these predicates, it limits the type of predicates that you can use. Specifically, HealthKit provides several predicate key paths (for example, HKPredicateKeyPathUUID and HKPredicateKeyPathMetadata). You can create predicates using only these key paths.

## Topics

### Accessing properties

- [predicate](healthkit/hkquery/predicate.md)
- [objectType](healthkit/hkquery/objecttype.md)
- [sampleType](healthkit/hkquery/sampletype.md)

### Creating object predicates

- [predicateForObject(with:)](healthkit/hkquery/predicateforobject(with:).md)
- [predicateForObjects(with:)](healthkit/hkquery/predicateforobjects(with:).md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-7j3p2.md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-89b4t.md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-9h87f.md)
- [predicateForObjects(withDeviceProperty:allowedValues:)](healthkit/hkquery/predicateforobjects(withdeviceproperty:allowedvalues:).md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-1ar4g.md)
- [predicateForObjects(withMetadataKey:)](healthkit/hkquery/predicateforobjects(withmetadatakey:).md)
- [predicateForObjects(withMetadataKey:allowedValues:)](healthkit/hkquery/predicateforobjects(withmetadatakey:allowedvalues:).md)
- [predicateForObjects(withMetadataKey:operatorType:value:)](healthkit/hkquery/predicateforobjects(withmetadatakey:operatortype:value:).md)
- [predicateForObjectsWithNoCorrelation()](healthkit/hkquery/predicateforobjectswithnocorrelation().md)

### Creating sample predicates

- [predicateForSamples(withStart:end:options:)](healthkit/hkquery/predicateforsamples(withstart:end:options:).md)
- [HKQueryOptions](healthkit/hkqueryoptions.md)

### Creating quantity sample predicates

- [predicateForQuantitySamples(with:quantity:)](healthkit/hkquery/predicateforquantitysamples(with:quantity:).md)

### Creating category sample predicates

- [predicateForCategorySamples(with:value:)](healthkit/hkquery/predicateforcategorysamples(with:value:).md)
- [HKCategoryValuePredicateProviding](healthkit/hkcategoryvaluepredicateproviding.md)

### Creating clinical record predicates

- [predicateForClinicalRecords(from:fhirResourceType:identifier:)](healthkit/hkquery/predicateforclinicalrecords(from:fhirresourcetype:identifier:).md)
- [predicateForClinicalRecords(withFHIRResourceType:)](healthkit/hkquery/predicateforclinicalrecords(withfhirresourcetype:).md)
- [predicateForVerifiableClinicalRecords(withRelevantDateWithin:)](healthkit/hkquery/predicateforverifiableclinicalrecords(withrelevantdatewithin:).md)

### Creating workout predicates

- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-5irg9.md)
- [predicateForWorkouts(with:)](healthkit/hkquery/predicateforworkouts(with:).md)
- [predicateForWorkouts(activityPredicate:)](healthkit/hkquery/predicateforworkouts(activitypredicate:).md)
- [predicateForWorkouts(with:duration:)](healthkit/hkquery/predicateforworkouts(with:duration:).md)
- [predicateForWorkouts(operatorType:quantityType:averageQuantity:)](healthkit/hkquery/predicateforworkouts(operatortype:quantitytype:averagequantity:).md)
- [predicateForWorkouts(operatorType:quantityType:maximumQuantity:)](healthkit/hkquery/predicateforworkouts(operatortype:quantitytype:maximumquantity:).md)
- [predicateForWorkouts(operatorType:quantityType:minimumQuantity:)](healthkit/hkquery/predicateforworkouts(operatortype:quantitytype:minimumquantity:).md)
- [predicateForWorkouts(operatorType:quantityType:sumQuantity:)](healthkit/hkquery/predicateforworkouts(operatortype:quantitytype:sumquantity:).md)
- [predicateForWorkouts(with:totalDistance:)](healthkit/hkquery/predicateforworkouts(with:totaldistance:).md)
- [predicateForWorkouts(with:totalEnergyBurned:)](healthkit/hkquery/predicateforworkouts(with:totalenergyburned:).md)
- [predicateForWorkouts(with:totalFlightsClimbed:)](healthkit/hkquery/predicateforworkouts(with:totalflightsclimbed:).md)
- [predicateForWorkouts(with:totalSwimmingStrokeCount:)](healthkit/hkquery/predicateforworkouts(with:totalswimmingstrokecount:).md)

### Creating workout activity predicates

- [predicateForWorkoutActivities(workoutActivityType:)](healthkit/hkquery/predicateforworkoutactivities(workoutactivitytype:).md)
- [predicateForWorkoutActivities(operatorType:duration:)](healthkit/hkquery/predicateforworkoutactivities(operatortype:duration:).md)
- [predicateForWorkoutActivities(start:end:options:)](healthkit/hkquery/predicateforworkoutactivities(start:end:options:).md)
- [predicateForWorkoutActivities(operatorType:quantityType:averageQuantity:)](healthkit/hkquery/predicateforworkoutactivities(operatortype:quantitytype:averagequantity:).md)
- [predicateForWorkoutActivities(operatorType:quantityType:maximumQuantity:)](healthkit/hkquery/predicateforworkoutactivities(operatortype:quantitytype:maximumquantity:).md)
- [predicateForWorkoutActivities(operatorType:quantityType:minimumQuantity:)](healthkit/hkquery/predicateforworkoutactivities(operatortype:quantitytype:minimumquantity:).md)
- [predicateForWorkoutActivities(operatorType:quantityType:sumQuantity:)](healthkit/hkquery/predicateforworkoutactivities(operatortype:quantitytype:sumquantity:).md)

### Creating activity summary predicates

- [predicateForActivitySummary(with:)](healthkit/hkquery/predicateforactivitysummary(with:).md)
- [predicate(forActivitySummariesBetweenStart:end:)](healthkit/hkquery/predicate(foractivitysummariesbetweenstart:end:).md)

### Creating electrocardiogram predicates

- [predicateForElectrocardiograms(classification:)](healthkit/hkquery/predicateforelectrocardiograms(classification:).md)
- [predicateForElectrocardiograms(symptomsStatus:)](healthkit/hkquery/predicateforelectrocardiograms(symptomsstatus:).md)
- [predicateForObjectsAssociated(electrocardiogram:)](healthkit/hkquery/predicateforobjectsassociated(electrocardiogram:).md)

### Creating predicate format strings

- [Predicate format strings](healthkit/predicate-format-strings.md)

### Creating sort descriptors

- [HealthKit sort descriptors](healthkit/healthkit-sort-descriptors.md)

### Type Methods

- [predicateForMedicationDoseEvent(medicationConceptIdentifier:)](healthkit/hkquery/predicateformedicationdoseevent(medicationconceptidentifier:).md)
- [predicateForMedicationDoseEvent(medicationConceptIdentifiers:)](healthkit/hkquery/predicateformedicationdoseevent(medicationconceptidentifiers:).md)
- [predicateForMedicationDoseEvent(scheduledDate:)](healthkit/hkquery/predicateformedicationdoseevent(scheduleddate:).md)
- [predicateForMedicationDoseEvent(scheduledDates:)](healthkit/hkquery/predicateformedicationdoseevent(scheduleddates:).md)
- [predicateForMedicationDoseEvent(scheduledStart:end:)](healthkit/hkquery/predicateformedicationdoseevent(scheduledstart:end:).md)
- [predicateForMedicationDoseEvent(status:)](healthkit/hkquery/predicateformedicationdoseevent(status:).md)
- [predicateForMedicationDoseEvent(statuses:)](healthkit/hkquery/predicateformedicationdoseevent(statuses:).md)
- [predicateForStatesOfMind(with:)](healthkit/hkquery/predicateforstatesofmind(with:)-3iyym.md)
- [predicateForStatesOfMind(with:)](healthkit/hkquery/predicateforstatesofmind(with:)-6obe4.md)
- [predicateForStatesOfMind(with:)](healthkit/hkquery/predicateforstatesofmind(with:)-9fny6.md)
- [predicateForStatesOfMind(withValence:operatorType:)](healthkit/hkquery/predicateforstatesofmind(withvalence:operatortype:).md)
- [predicateForUserAnnotatedMedications(hasSchedule:)](healthkit/hkquery/predicateforuserannotatedmedications(hasschedule:).md)
- [predicateForUserAnnotatedMedications(isArchived:)](healthkit/hkquery/predicateforuserannotatedmedications(isarchived:).md)
- [predicateForWorkoutEffortSamplesRelated(workout:activity:)](healthkit/hkquery/predicateforworkouteffortsamplesrelated(workout:activity:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [HKActivitySummaryQuery](healthkit/hkactivitysummaryquery.md)
- [HKAnchoredObjectQuery](healthkit/hkanchoredobjectquery.md)
- [HKCorrelationQuery](healthkit/hkcorrelationquery.md)
- [HKDocumentQuery](healthkit/hkdocumentquery.md)
- [HKElectrocardiogramQuery](healthkit/hkelectrocardiogramquery.md)
- [HKHeartbeatSeriesQuery](healthkit/hkheartbeatseriesquery.md)
- [HKObserverQuery](healthkit/hkobserverquery.md)
- [HKQuantitySeriesSampleQuery](healthkit/hkquantityseriessamplequery.md)
- [HKSampleQuery](healthkit/hksamplequery.md)
- [HKSourceQuery](healthkit/hksourcequery.md)
- [HKStatisticsCollectionQuery](healthkit/hkstatisticscollectionquery.md)
- [HKStatisticsQuery](healthkit/hkstatisticsquery.md)
- [HKUserAnnotatedMedicationQuery](healthkit/hkuserannotatedmedicationquery.md)
- [HKVerifiableClinicalRecordQuery](healthkit/hkverifiableclinicalrecordquery.md)
- [HKWorkoutEffortRelationshipQuery](healthkit/hkworkouteffortrelationshipquery.md)
- [HKWorkoutRouteQuery](healthkit/hkworkoutroutequery.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Related Documentation

- [HKActivitySummaryQuery](healthkit/hkactivitysummaryquery.md)
- [HKAnchoredObjectQuery](healthkit/hkanchoredobjectquery.md)
- [HKDocumentQuery](healthkit/hkdocumentquery.md)
- [HKObserverQuery](healthkit/hkobserverquery.md)
- [HKSourceQuery](healthkit/hksourcequery.md)
- [HKStatisticsQuery](healthkit/hkstatisticsquery.md)
- [HKStatisticsCollectionQuery](healthkit/hkstatisticscollectionquery.md)
- [HKWorkoutRouteQuery](healthkit/hkworkoutroutequery.md)

### Basic queries

- [HKSampleQueryDescriptor](healthkit/hksamplequerydescriptor.md)
- [HKSampleQuery](healthkit/hksamplequery.md)
- [HKCorrelationQuery](healthkit/hkcorrelationquery.md)
- [HKQueryDescriptor](healthkit/hkquerydescriptor.md)
