---
title: HKSamplePredicate
framework: healthkit
role: symbol
role_heading: Structure
path: healthkit/hksamplepredicate
---

# HKSamplePredicate

A predicate for queries that return a collection of matching sample objects.

## Declaration

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

## Overview

Overview The HKSamplePredicate structure bundles an HKSampleType and an optional NSPredicate. The structure is generic. You can create it for any HKSampleType subclass, and it automatically sets the Sample type to the matching HKSampleType subtype. As a result, any query that you build using this structure returns properly typed results. To create an HKSamplePredicate instance, call one of its constructor methods. let stepType = HKQuantityType(.stepCount) let predicate = HKSamplePredicate.quantitySample(type: stepType)

let descriptor = HKSampleQueryDescriptor(     predicates:[predicate],     sortDescriptors: [],     limit: 10)

// The results are an array of HKQuantitySample objects. let results = try await descriptor.result(for: store)

## Topics

### Creating Sample Predicates

- [audiogram(_:)](healthkit/hksamplepredicate/audiogram(_:).md)
- [categorySample(type:predicate:)](healthkit/hksamplepredicate/categorysample(type:predicate:).md)
- [clinicalRecord(type:predicate:)](healthkit/hksamplepredicate/clinicalrecord(type:predicate:).md)
- [correlation(type:predicate:)](healthkit/hksamplepredicate/correlation(type:predicate:).md)
- [electrocardiogram(_:)](healthkit/hksamplepredicate/electrocardiogram(_:).md)
- [heartbeatSeries(_:)](healthkit/hksamplepredicate/heartbeatseries(_:).md)
- [quantitySample(type:predicate:)](healthkit/hksamplepredicate/quantitysample(type:predicate:).md)
- [sample(type:predicate:)](healthkit/hksamplepredicate/sample(type:predicate:).md)
- [visionPrescription(_:)](healthkit/hksamplepredicate/visionprescription(_:).md)
- [workout(_:)](healthkit/hksamplepredicate/workout(_:).md)
- [workoutRoute(_:)](healthkit/hksamplepredicate/workoutroute(_:).md)

### Accessing Sample Predicate Data

- [nsPredicate](healthkit/hksamplepredicate/nspredicate.md)
- [sampleType](healthkit/hksamplepredicate/sampletype.md)

### Type Methods

- [gad7Assessment(_:)](healthkit/hksamplepredicate/gad7assessment(_:).md)
- [phq9Assessment(_:)](healthkit/hksamplepredicate/phq9assessment(_:).md)
- [stateOfMind(_:)](healthkit/hksamplepredicate/stateofmind(_:).md)

## Relationships

### Conforms To

- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Swift concurrency support

- [Running Queries with Swift Concurrency](healthkit/running-queries-with-swift-concurrency.md)
- [HKAsyncQuery](healthkit/hkasyncquery.md)
- [HKAsyncSequenceQuery](healthkit/hkasyncsequencequery.md)
