<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKSampleQuery",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKSampleQuery"
  },
  "title" : "HKSampleQuery"
}
-->

# HKSampleQuery

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

```
class HKSampleQuery
```

## Overview

You can use sample queries to search for any concrete subclasses of the [`HKSample`](/documentation/HealthKit/HKSample) class, including [`HKCategorySample`](/documentation/HealthKit/HKCategorySample), [`HKCorrelation`](/documentation/HealthKit/HKCorrelation), [`HKQuantitySample`](/documentation/HealthKit/HKQuantitySample), and [`HKWorkout`](/documentation/HealthKit/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`](/documentation/HealthKit/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 ``doc://com.apple.healthkit/documentation/HealthKit/HKSampleQuery`` class.

## Topics

### Creating Sample Queries

  <doc://com.apple.healthkit/documentation/HealthKit/executing-sample-queries>

[`-  initWithSampleType:predicate:limit:sortDescriptors:resultsHandler:`](/documentation/HealthKit/HKSampleQuery/init(sampleType:predicate:limit:sortDescriptors:resultsHandler:))

Instantiates and returns a sample query.

[`-  initWithQueryDescriptors:limit:resultsHandler:`](/documentation/HealthKit/HKSampleQuery/init(queryDescriptors:limit:resultsHandler:))

Creates a query for samples that match any of the descriptors you provided.

[`-  initWithQueryDescriptors:limit:sortDescriptors:resultsHandler:`](/documentation/HealthKit/HKSampleQuery/init(queryDescriptors:limit:sortDescriptors:resultsHandler:))

Creates a query for samples that match any of the query descriptors you provided, sorted by the sort descriptors you provided.

[`HKObjectQueryNoLimit`](/documentation/HealthKit/HKObjectQueryNoLimit)

A value indicating that the query returns all the matching samples in the HealthKit store.

  <doc://com.apple.healthkit/documentation/HealthKit/healthkit-sort-descriptors>

### Getting Property Data

[`limit`](/documentation/HealthKit/HKSampleQuery/limit)

The maximum number of samples that this query returns.

[`sortDescriptors`](/documentation/HealthKit/HKSampleQuery/sortDescriptors)

The sort descriptors that specify the order of the results returned by this query.

### Setting Limits

[`HKObjectQueryNoLimit`](/documentation/HealthKit/HKObjectQueryNoLimit)

A value indicating that the query returns all the matching samples in the HealthKit store.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Inherits From

[`HKQuery`](/documentation/HealthKit/HKQuery)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)