Initializes a statistics query instance that performs the specified calculations over the matching samples in the HeathKit store.
- iOS 8.0+
- Mac Catalyst 13.0+
- watchOS 2.0+
The type of sample to search for. This type must be an instance of the
HKQuantityclass. You cannot perform statistics queries using other sample types.
A predicate that limits the results returned by the query. You can pass
nilif you want to perform the statistical calculation over all the samples of the specified type.
A list of options that define the type of statistical calculations performed and the way in which data from multiple sources are merged. For a list of valid options, see
A block that is called after the statistical calculations are complete. This block takes the following arguments:
A reference to the query calling this block.
A HealthKit statistics object that contains the requested statistical data, or
nilif an error occurs.
If an error occurs, this parameter contains an object describing the error; otherwise, it is
A newly initialized statistics query object.
After instantiating the query, call the
execute method to run this query. Queries run on an anonymous background queue. As soon as the query is complete, the results handler is executed on the same background queue (but not necessarily on the same thread). You typically dispatch these results to the main queue to update the user interface.