In our last tutorial we looked at the HKStatisticsQuery which is used to perform statistical calculations on sets of matching samples. In todays tutorial we will investigate the HKStatisticsCollectionQuery.
This particular query is useful for creating graphs. Unlike the HKStatisticsQuery which could only run one statistical calculation on one set of matching samples, the HKStatisticsCollectionQuery can perform these calculations over a series of fixed-length time intervals. This allows us to query samples such as step counts and fetch the cumulative sum in 1 hour intervals over a period of time set by the predicate.
This particular query can also be long-lived if needed, meaning that any changes made in Apple Health will be recognised, and you will be notified so that you can act. [Read more…]