Search code examples
swifthealthkithksamplequery

HKQueryOptions in predicate


I am trying to use a predicate to take the data from the last 30 days from HealthKit. Many of the tutorials online use .None as their HKQueryOption, and as I am unfamiliar with HKQueryOptions, I was wondering if anyone else knew what could replace .None in this instance. Currently, I have put in .None as the HKQueryOptions but this causes my error. 'None' is unavailable: use [] to construct an empty option set When I put in [] instead, and print results it comes back as []

Here is my query function where I declare the predicate

let sampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodGlucose)
        let mostRecentPredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options:.None)
        let query = HKSampleQuery(sampleType: sampleType!, predicate: mostRecentPredicate, limit: 35, sortDescriptors: nil) { (query, results, error) in

Solution

  • Try using the empty set literal [] instead of .None:

    let mostRecentPredicate = HKQuery.predicateForSamples(withStart: startDate, end:endDate, options:[])