Instantiates and returns a correlation query.
- iOS 8.0+
- Mac Catalyst 13.0+Beta
- watchOS 2.0+
The type of correlation to search for.
A predicate that limits the results returned by the query. This predicate is compared with the correlation objects. Pass
nilto receive all the correlations of the specified type.
A dictionary whose keys are
HKSampleinstances, and whose values are
NSPredicateinstances. The query iterates over all the samples in the correlation. For each sample, it looks up the corresponding predicate based on the sample’s type and then evaluates that predicate against the sample. If the dictionary does not contain a matching sample type, the query treats it as a
nilpredicate, and accepts the sample.
Three things must be true if this query is going to match a correlation:
The correlation object must match the provided predicate parameter.
For each key in the sample predicate dictionary, the correlation must contain a sample whose type matches the key. In other words, the keys from the sample predicate dictionary define the set of required samples for the correlation.
For each sample in the correlation, use the sample’s type to look up its predicate in the sample predicate dictionary. If the dictionary contains a matching predicate, the sample must match that predicate. If the dictionary does not contain a matching predicate, the sample is ignored (it can have any value).
A block that is called when the query finishes executing. This block takes the following parameters:
A reference to the query that called this block.
An array containing the correlations found by the query, or
nilif an error occurs.
If an error occurred, this parameter contains an object describing the error; otherwise, it is
A newly initialized correlation object.
After instantiating the query, run it by calling the
execute(_:) method. Queries run on a background thread. As soon as the query is complete, the results handler is executed on the background thread. You typically dispatch these results to the main thread to update the user interface.