<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKActivitySummaryQuery/init(predicate:resultsHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKActivitySummaryQuery(im)initWithPredicate:resultsHandler:"
  },
  "title" : "init(predicate:resultsHandler:)"
}
-->

# init(predicate:resultsHandler:)

Initializes a new active summary query.

```
init(predicate: NSPredicate?, resultsHandler handler: @escaping @Sendable (HKActivitySummaryQuery, [HKActivitySummary]?, (any Error)?) -> Void)
```

## Parameters

`predicate`

A predicate that filters the activity summaries returned by the query. Pass `nil` to receive all activity samples.

`handler`

A block that is called after the initial results have been gathered. This block takes the following parameters:

- query: A reference to the query calling this block.
- activitySummaries: An array containing the summaries returned by this query, or `nil` if an error occurred.
- error: If an error occurs, this parameter contains an object describing the error; otherwise, it is `nil`.

## Return Value

A newly initialized activity summary query.

## Discussion

After instantiating the query, call the [`HKHealthStore`](/documentation/HealthKit/HKHealthStore) class’s [`execute(_:)`](/documentation/HealthKit/HKHealthStore/execute(_:)) method to run it. The queries run on an anonymous background queue. As soon as the query is complete, the results handler block is executed on the same background queue (but not necessarily the same thread). You typically dispatch these results to the main queue to update the user interface.

Activity summary queries can also act as long-running queries. If you assign an update handler before you execute the query, the query continues to monitor the HealthKit store after gathering the initial results. The update handler is called on a background queue every time a matching sample is saved or updated in the HealthKit store. You can cancel this query by calling the store’s [`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)