swiftui - Swift Health Kit 查询
问题描述
calculateBloosPresureData
我的文件中有这个功能HealthStore
。我收到错误消息。
Cannot convert value of type '[HKSample]?' to expected argument type 'HKQuantitySample?'
就行了 completion(statisticsCollection)
。我想在内容视图中使用数据,但无法正常工作。
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)
}
}
解决方案
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(...)
推荐阅读
- python - 计算数据框中组之间的欧几里得距离
- c - PostgreSQL 自定义 C 函数导入失败:“sprintf_chk:未找到符号”
- c++ - 命名空间范围内的 constexpr 变量,没有显式内联定义,并且
- java - 如何使用带有字符串输入的 JAXB 2.0 禁用 DTD 获取
- python - 如何使用 boto3 从特定对象开始循环遍历 s3 存储桶?
- python - Python Open file not creating new file
- jestjs - Eslint jest/globals 环境密钥未知
- jquery - 限制用户在使用 wordpress 媒体编辑器选择特色图像时裁剪图像
- .net - 如何制作拆箱设置器表达式?
- hyperledger-fabric - 如何更正 Hyperledger Explorer 的数据库访问错误?