Skip to content

Instantly share code, notes, and snippets.

View tshortli's full-sized avatar

Allan Shortlidge tshortli

View GitHub Profile
@tshortli
tshortli / healthkit-async-await-workouts.swift
Last active January 31, 2022 08:30
A Swift async function that gets the most recent workouts from HealthKit
func mostRecentWorkouts(for healthStore: HKHealthStore, limit: Int) async throws -> [HKWorkout] {
let query = HKSampleQueryDescriptor(
predicates: [.workout()],
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)],
limit: limit
)
return try await query.result(for: healthStore)
}