HKStatisticsCollectionQueryDescriptor document example is not executed.

let stepType = HKQuantityType(.stepCount)

        let stepsThisWeek = HKSamplePredicate.quantitySample(type: stepType, predicate: thisWeek)

        let yesterday = calendar.date(byAdding: .day, value: -1, to: calendar.startOfDay(for: now))

        let every5 = DateComponents(minute:5)

        let healthTypes = Set([

            HKCategoryType.categoryType(forIdentifier: .handwashingEvent)!

        ])

        let sumOfStepsQuery = HKStatisticsCollectionQueryDescriptor(

            predicate: stepsThisWeek,

            options: .cumulativeSum,

            anchorDate: endDate,

            intervalComponents: every5)

        do {

            let updateQueue = sumOfStepsQuery.results(for: store)

            // Wait for the initial results and updates.

            updateQueue = Task {

                for try await results in updateQueue {

                    // Use the statistics collection here.

                }

            }

            

        } catch {

            //handle error

            print(error)

        }
HKStatisticsCollectionQueryDescriptor document example is not executed.
 
 
Q