Contents

HKSamplePredicate

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

Declaration

struct HKSamplePredicate<Sample> where Sample : HKSample

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

Accessing Sample Predicate Data

Type Methods

See Also

Swift concurrency support