<!--
{
  "availability" : [
    "iOS: 15.4.0 -",
    "iPadOS: 15.4.0 -",
    "macCatalyst: 15.4.0 -",
    "macOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 8.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKSampleQueryDescriptor",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "s:9HealthKit23HKSampleQueryDescriptorV"
  },
  "title" : "HKSampleQueryDescriptor"
}
-->

# HKSampleQueryDescriptor

A query interface that reads samples using Swift concurrency.

```
struct HKSampleQueryDescriptor<Sample> where Sample : HKSample
```

## Overview

Use [`HKSampleQueryDescriptor`](/documentation/HealthKit/HKSampleQueryDescriptor) to run a general query that returns a snapshot of all the matching samples currently saved in the HealthKit store.

```swift
// Define the type.
let stepType = HKQuantityType(.stepCount)

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

// Launch the query and wait for the results.
// The system automatically sets results to [HKQuantitySample].
let results = try await descriptor.result(for: store)

for result in results {
    // Process the results here.
}
```

When you call the descriptor’s [`result(for:)`](/documentation/HealthKit/HKSampleQueryDescriptor/result(for:)) method, it creates and executes an [`HKSampleQuery`](/documentation/HealthKit/HKSampleQuery) in the background, passing the results from the query’s `resultsHandler` as its return value.

## Topics

### Creating Query Descriptors

[`init(predicates:sortDescriptors:limit:)`](/documentation/HealthKit/HKSampleQueryDescriptor/init(predicates:sortDescriptors:limit:))

Creates a sample query descriptor.

### Running Queries

[`result(for:)`](/documentation/HealthKit/HKSampleQueryDescriptor/result(for:))

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

### Accessing Query Properties

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

The maximum number of samples that the query returns.

[`predicates`](/documentation/HealthKit/HKSampleQueryDescriptor/predicates)

An array of sample predicates that define the type of data that the query returns.

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

An array that specifies the order of the results that the query returns.



---

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)