0

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
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Johnd
  • 584
  • 2
  • 6
  • 21
  • 2
    Please add the error in your question – Dat Nguyen Jun 20 '17 at 04:06
  • I added the error and what I tried after that @DatNguyen – Johnd Jun 21 '17 at 16:50
  • I'm no expert in this subject matter, but when you use `[]`, see no error, and get back `[]`, it means: 1) The query is in correct format; and 2) Empty result means that there's no matched result for your query. Why did you get empty result? Maybe there's no data in your HealthKit in the last 30 days. Maybe there's no data at all. You'll need to figure this out yourself :) – Dat Nguyen Jun 22 '17 at 05:13

1 Answers1

0

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

let mostRecentPredicate = HKQuery.predicateForSamples(withStart: startDate, end:endDate, options:[])
Allan
  • 7,039
  • 1
  • 16
  • 26