Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swiftui Swift健康工具包查询_Swiftui_Healthkit - Fatal编程技术网

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) {
   ...
或者在调用外部
完成(…)