Replies: 1 comment
-
@vinepb we already have this: as part of the 1.0 release of SpeziHealthKit, the public protocol HealthKitConstraint: Standard {
/// Notifies the `Standard` about the addition of a batch of HealthKit `HKSample` samples.
/// - parameter addedSamples: The `HKSample`s that were added to the HealthKit database.
/// - parameter sampleType: The ``SampleType`` of the new samples
func handleNewSamples<Sample>(
_ addedSamples: some Collection<Sample>,
ofType sampleType: SampleType<Sample>
) async
/// Notifies the `Standard` about the removal of a batch of HealthKit objects.
/// - parameter deletedObjects: The `HKDeletedObject`s that were removed from the HealthKit database
/// - parameter sampleType: The ``SampleType`` of the deleted objects
func handleDeletedObjects<Sample>(
_ deletedObjects: some Collection<HKDeletedObject>,
ofType sampleType: SampleType<Sample>
) async
} which will provide all new/deleted objects at once, on a per-sample-type basis based on the interface you're describing (with every new/deleted sample being passed to the standard on its own), i think you're running an outdated pre-1.0 version. also, regarding your question about integration with SwiftData: depending on your specific use case it might be more efficient to simply fetch the data from HealthKit on demand, instead of syncing it with SwiftData. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What Stanford Spezi module is your idea related to?
SpeziHealthKit
Use Case
Provide final hook to notify the
Standard
that processing of a batch of HealthKit updates (both additions and removals) has completed, to be used with anchored queries.Problem
When using SpeziHealthKit with SwiftData, I found it unoptimized to leave auto save on, or to perform a save with each new sample when creating and storing custom data points, while using anchored queries.
Solution
The idea to simply add a new method to the
HealthKitConstraint
protocol to be called at the end of batch updates. Example:Then in
HKHealthStore+AnchoredObjectQuery.swift
:Similarly, in
HealthKitSampleCollector.swift
:Then an example usage scenario would be:
Alternatives considered
Haven't found a better alternative to integrate with SwiftData, but am open to suggestions.
Additional context
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions