<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKHealthStore/execute(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKHealthStore(im)executeQuery:"
  },
  "title" : "execute(_:)"
}
-->

# execute(_:)

Starts executing the provided query.

```
func execute(_ query: HKQuery)
```

## Parameters

`query`

A concrete subclass of the [`HKQuery`](/documentation/HealthKit/HKQuery) class (any of the classes [`HKSampleQuery`](/documentation/HealthKit/HKSampleQuery), [`HKAnchoredObjectQuery`](/documentation/HealthKit/HKAnchoredObjectQuery), [`HKCorrelationQuery`](/documentation/HealthKit/HKCorrelationQuery), [`HKObserverQuery`](/documentation/HealthKit/HKObserverQuery), [`HKSourceQuery`](/documentation/HealthKit/HKSourceQuery), [`HKStatisticsQuery`](/documentation/HealthKit/HKStatisticsQuery), or [`HKStatisticsCollectionQuery`](/documentation/HealthKit/HKStatisticsCollectionQuery)).

## Discussion

HealthKit executes queries asynchronously on a background queue. Most queries automatically stop after they have finished executing. However, long-running queries—such as observer queries and some statistics collection queries—continue to execute in the background. To stop long-running queries, call the [`stop(_:)`](/documentation/HealthKit/HKHealthStore/stop(_:)) method.

---

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)