---
title: "init(type:predicate:anchor:limit:completionHandler:)"
framework: healthkit
role: symbol
role_heading: Initializer
path: "healthkit/hkanchoredobjectquery/init(type:predicate:anchor:limit:completionhandler:)"
---

# init(type:predicate:anchor:limit:completionHandler:)

Initializes a new anchored object query.

## Declaration

```swift
init(type: HKSampleType, predicate: NSPredicate?, anchor: Int, limit: Int, completionHandler handler: @escaping @Sendable (HKAnchoredObjectQuery, [HKSample]?, Int, (any Error)?) -> Void)
```

## Parameters

- `type`: The type of sample to search for. This query supports all sample types. Specifically, you can pass any concrete subclass of the doc://com.apple.healthkit/documentation/HealthKit/HKSampleType class (the doc://com.apple.healthkit/documentation/HealthKit/HKQuantityType, doc://com.apple.healthkit/documentation/HealthKit/HKCategoryType, doc://com.apple.healthkit/documentation/HealthKit/HKWorkoutType, and doc://com.apple.healthkit/documentation/HealthKit/HKCorrelationType classes).
- `predicate`: A predicate that filters the samples returned by the query. Pass nil to receive all the new samples of the specified type.
- `anchor`: The anchor returned by the previous anchored object query. The anchor value corresponds to the last sample that was returned by the previous anchored object query. The new query returns only objects newer than that sample.
- `limit`: The maximum number of samples received by the query. To receive all of the new samples, pass doc://com.apple.healthkit/documentation/HealthKit/HKObjectQueryNoLimit.
- `handler`: A block that is called when the query finishes executing. This block takes the following parameters:

## Return Value

Return Value A newly initialized anchor query object.

## Discussion

Discussion After instantiating the query, call the HKHealthStore class’s execute(_:) method to run it. The queries run on an anonymous background queue. As soon as the query is complete, the handler is executed on the same background queue (but not necessarily the same thread).

## Topics

### Constants

- [HKAnchoredObjectQueryNoAnchor](healthkit/hkanchoredobjectquerynoanchor.md)

## See Also

### Creating Anchored Object Queries

- [Executing Anchored Object Queries](healthkit/executing-anchored-object-queries.md)
- [init(type:predicate:anchor:limit:resultsHandler:)](healthkit/hkanchoredobjectquery/init(type:predicate:anchor:limit:resultshandler:).md)
- [init(queryDescriptors:anchor:limit:resultsHandler:)](healthkit/hkanchoredobjectquery/init(querydescriptors:anchor:limit:resultshandler:).md)
- [HKObjectQueryNoLimit](healthkit/hkobjectquerynolimit.md)
