---
title: HKSampleQueryDescriptor
framework: healthkit
role: symbol
role_heading: Structure
path: healthkit/hksamplequerydescriptor
---

# HKSampleQueryDescriptor

A query interface that reads samples using Swift concurrency.

## Declaration

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

## Mentioned in

Reading data from HealthKit Running Queries with Swift Concurrency

## Overview

Overview Use HKSampleQueryDescriptor to run a general query that returns a snapshot of all the matching samples currently saved in the HealthKit store. // 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:) method, it creates and executes an HKSampleQuery in the background, passing the results from the query’s resultsHandler as its return value.

## Topics

### Creating Query Descriptors

- [init(predicates:sortDescriptors:limit:)](healthkit/hksamplequerydescriptor/init(predicates:sortdescriptors:limit:).md)

### Running Queries

- [result(for:)](healthkit/hksamplequerydescriptor/result(for:).md)

### Accessing Query Properties

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

### Default Implementations

- [HKAsyncQuery Implementations](healthkit/hksamplequerydescriptor/hkasyncquery-implementations.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [HKAsyncQuery](healthkit/hkasyncquery.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Basic queries

- [HKSampleQuery](healthkit/hksamplequery.md)
- [HKCorrelationQuery](healthkit/hkcorrelationquery.md)
- [HKQueryDescriptor](healthkit/hkquerydescriptor.md)
- [HKQuery](healthkit/hkquery.md)
