---
title: HKSampleQuery
framework: healthkit
role: symbol
role_heading: Class
path: healthkit/hksamplequery
---

# HKSampleQuery

A general query that returns a snapshot of all the matching samples currently saved in the HealthKit store.

## Declaration

```swift
class HKSampleQuery
```

## Mentioned in

Executing Observer Queries

## Overview

Overview You can use sample queries to search for any concrete subclasses of the HKSample class, including HKCategorySample, HKCorrelation, HKQuantitySample, and HKWorkout objects. The sample query returns sample objects that match the provided type and predicate. You can provide a sort order for the returned samples, or limit the number of samples returned. Other query classes can be used to perform more specialized searches and calculations. For more information, see HKQuery. Sample queries are immutable: The query’s properties are set when the query is first created, and they can’t change. note: As with many HealthKit classes, don’t subclass the HKSampleQuery class.

## Topics

### Creating Sample Queries

- [Executing Sample Queries](healthkit/executing-sample-queries.md)
- [init(sampleType:predicate:limit:sortDescriptors:resultsHandler:)](healthkit/hksamplequery/init(sampletype:predicate:limit:sortdescriptors:resultshandler:).md)
- [init(queryDescriptors:limit:resultsHandler:)](healthkit/hksamplequery/init(querydescriptors:limit:resultshandler:).md)
- [init(queryDescriptors:limit:sortDescriptors:resultsHandler:)](healthkit/hksamplequery/init(querydescriptors:limit:sortdescriptors:resultshandler:).md)
- [HKObjectQueryNoLimit](healthkit/hkobjectquerynolimit.md)
- [HealthKit sort descriptors](healthkit/healthkit-sort-descriptors.md)

### Getting Property Data

- [limit](healthkit/hksamplequery/limit.md)
- [sortDescriptors](healthkit/hksamplequery/sortdescriptors.md)

### Setting Limits

- [HKObjectQueryNoLimit](healthkit/hkobjectquerynolimit.md)

## Relationships

### Inherits From

- [HKQuery](healthkit/hkquery.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

### Basic queries

- [HKSampleQueryDescriptor](healthkit/hksamplequerydescriptor.md)
- [HKCorrelationQuery](healthkit/hkcorrelationquery.md)
- [HKQueryDescriptor](healthkit/hkquerydescriptor.md)
- [HKQuery](healthkit/hkquery.md)
