Reputation: 21
i have the function calculateBloosPresureData
in my file HealthStore
. I am getting the error.
Cannot convert value of type '[HKSample]?' to expected argument type 'HKQuantitySample?'
on the line completion(statisticsCollection)
. I want to use the data in the content view but can't get this to work.
func calculateBloosPresureData(completion: @escaping (HKQuantitySample?) -> Void) {
let presureType = HKQuantityType.correlationType(forIdentifier: .bloodPressure)!
let startDate = Calendar.current.date(byAdding: .day, value: -7, to: Date())
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: Date(), options: .strictStartDate)
query = HKSampleQuery(sampleType: presureType,
predicate: predicate,
limit: HKObjectQueryNoLimit,
sortDescriptors: nil) { (query, statisticsCollection, error) in
completion(statisticsCollection)
print(statisticsCollection!)
}
if let healthstore = healthStore, let query = self.query {
healthstore.execute(query)
}
}
Upvotes: 1
Views: 170
Reputation: 257503
Your completion signature does not meat HQSampleQuery
completion results, so just change it
func calculateBloosPresureData(completion: @escaping ([HKSample]?) -> Void) {
...
or transform results as needed before call to external completion(...)
Upvotes: 1