Forked from tshortli/healthkit-async-await-workouts.swift
Created
January 28, 2022 09:26
-
-
Save wb-towa/eb457b2567a0fba5bc51e0f41ab70dee to your computer and use it in GitHub Desktop.
A Swift async function that gets the most recent workouts from HealthKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment