diff --git a/Sources/SpeziHealthKit/CollectSample/CollectSample.swift b/Sources/SpeziHealthKit/CollectSample/CollectSample.swift index 39e794d..8dccf96 100644 --- a/Sources/SpeziHealthKit/CollectSample/CollectSample.swift +++ b/Sources/SpeziHealthKit/CollectSample/CollectSample.swift @@ -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(_ sampleType: S, deliverySetting: HealthKitDeliverySetting = .manual()) { - self.collectSamples = CollectSamples([sampleType], deliverySetting: deliverySetting) + public init( + _ sampleType: S, + predicate: NSPredicate? = nil, + deliverySetting: HealthKitDeliverySetting = .manual() + ) { + self.collectSamples = CollectSamples([sampleType], predicate: predicate, deliverySetting: deliverySetting) } diff --git a/Sources/SpeziHealthKit/CollectSample/CollectSamples.swift b/Sources/SpeziHealthKit/CollectSample/CollectSamples.swift index c9be574..1f679b6 100644 --- a/Sources/SpeziHealthKit/CollectSample/CollectSamples.swift +++ b/Sources/SpeziHealthKit/CollectSample/CollectSamples.swift @@ -13,14 +13,23 @@ import Spezi /// Collects `HKSampleType`s in the ``HealthKit`` component. public struct CollectSamples: HealthKitDataSourceDescription { public let sampleTypes: Set + 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, deliverySetting: HealthKitDeliverySetting = .manual()) { + public init( + _ sampleTypes: Set, + predicate: NSPredicate? = nil, + deliverySetting: HealthKitDeliverySetting = .manual() + ) { self.sampleTypes = sampleTypes + self.predicate = predicate self.deliverySetting = deliverySetting } @@ -35,6 +44,7 @@ public struct CollectSamples: HealthKitDataSourceDescription { healthStore: healthStore, standard: standard, sampleType: sampleType, + predicate: predicate, deliverySetting: deliverySetting, adapter: adapter )