Post

Replies

Boosts

Views

Activity

Reply to Dive workout
One approach is to use the following function as a starting point. It returns a TimeInterval array. First, it creates a predicate for only dive workouts and queries them. Using .map it builds a TimeInterval (durations) array for those workouts. The count of this array is the number of dives. The total dive time can be calculated with .reduce to sum the array. func divingWorkoutDurations(store: HKHealthStore) async throws -> [TimeInterval] { let predicate = HKQuery.predicateForWorkouts(with: .underwaterDiving) let descriptor = HKSampleQueryDescriptor( predicates: [.workout(predicate)], sortDescriptors: [] ) let diveWorkoutDurations = try await descriptor.result(for: store).map { $0.duration } return diveWorkoutDurations } let totalDiveTime = durations.reduce(0, +)
3w
Reply to Dive workout
One approach is to use the following function as a starting point. It returns a TimeInterval array. First, it creates a predicate for only dive workouts and queries them. Using .map it builds a TimeInterval (durations) array for those workouts. The count of this array is the number of dives. The total dive time can be calculated with .reduce to sum the array. func divingWorkoutDurations(store: HKHealthStore) async throws -> [TimeInterval] { let predicate = HKQuery.predicateForWorkouts(with: .underwaterDiving) let descriptor = HKSampleQueryDescriptor( predicates: [.workout(predicate)], sortDescriptors: [] ) let diveWorkoutDurations = try await descriptor.result(for: store).map { $0.duration } return diveWorkoutDurations } let totalDiveTime = durations.reduce(0, +)
Replies
Boosts
Views
Activity
3w