Swiftui Swift健康工具包查询
我的文件Swiftui Swift健康工具包查询,swiftui,healthkit,Swiftui,Healthkit,我的文件HealthStore中有函数calculateBloosPresureData。我得到了错误 Cannot convert value of type '[HKSample]?' to expected argument type 'HKQuantitySample?' 在线完成(统计收集)。我想使用内容视图中的数据,但无法使其正常工作 func calculateBloosPresureData(completion: @escaping (HKQuantitySample?)
HealthStore
中有函数calculateBloosPresureData
。我得到了错误
Cannot convert value of type '[HKSample]?' to expected argument type 'HKQuantitySample?'
在线完成(统计收集)
。我想使用内容视图中的数据,但无法使其正常工作
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)
}
}
您的完成签名不包含
HQSampleQuery
完成结果,所以只需更改它即可
func calculateBloosPresureData(completion: @escaping ([HKSample]?) -> Void) {
...
或者在调用外部完成(…)