Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a Custom Predicate for HealthKit Data Collection #5

Merged
merged 2 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/SpeziHealthKit/CollectSample/CollectSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ public struct CollectSample: HealthKitDataSourceDescription {

/// - Parameters:
/// - sampleType: The `HKSampleType` that should be collected
/// - predicate: A custom predicate that should be passed to the HealthKit query.
/// The default predicate collects all samples that have been collected from the first time that the user
/// provided the application authorization to collect the samples.
/// - deliverySetting: The ``HealthKitDeliverySetting`` that should be used to collect the sample type. `.manual` is the default argument used.
public init<S: HKSampleType>(_ sampleType: S, deliverySetting: HealthKitDeliverySetting = .manual()) {
self.collectSamples = CollectSamples([sampleType], deliverySetting: deliverySetting)
public init<S: HKSampleType>(
_ sampleType: S,
predicate: NSPredicate? = nil,
deliverySetting: HealthKitDeliverySetting = .manual()
) {
self.collectSamples = CollectSamples([sampleType], predicate: predicate, deliverySetting: deliverySetting)
}


Expand Down
12 changes: 11 additions & 1 deletion Sources/SpeziHealthKit/CollectSample/CollectSamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ import Spezi
/// Collects `HKSampleType`s in the ``HealthKit`` component.
public struct CollectSamples: HealthKitDataSourceDescription {
public let sampleTypes: Set<HKSampleType>
let predicate: NSPredicate?
let deliverySetting: HealthKitDeliverySetting


/// - Parameters:
/// - sampleType: The set of `HKSampleType`s that should be collected
/// - predicate: A custom predicate that should be passed to the HealthKit query.
/// The default predicate collects all samples that have been collected from the first time that the user
/// provided the application authorization to collect the samples.
/// - deliverySetting: The ``HealthKitDeliverySetting`` that should be used to collect the sample type. `.manual` is the default argument used.
public init(_ sampleTypes: Set<HKSampleType>, deliverySetting: HealthKitDeliverySetting = .manual()) {
public init(
_ sampleTypes: Set<HKSampleType>,
predicate: NSPredicate? = nil,
deliverySetting: HealthKitDeliverySetting = .manual()
) {
self.sampleTypes = sampleTypes
self.predicate = predicate
self.deliverySetting = deliverySetting
}

Expand All @@ -35,6 +44,7 @@ public struct CollectSamples: HealthKitDataSourceDescription {
healthStore: healthStore,
standard: standard,
sampleType: sampleType,
predicate: predicate,
deliverySetting: deliverySetting,
adapter: adapter
)
Expand Down