Skip to content

Commit

Permalink
Pass a Custom Predicate for HealthKit Data Collection (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSchmiedmayer authored May 23, 2023
1 parent d03eabc commit 7ae7c34
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 7ae7c34

Please # to comment.