Swift 健康服务查询
Swift Health Kit Query
我的文件 HealthStore
中有函数 calculateBloosPresureData
。我收到错误消息。
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)
}
}
你的补全签名不包含 HQSampleQuery
补全结果,所以只需更改它
func calculateBloosPresureData(completion: @escaping ([HKSample]?) -> Void) {
...
或在调用外部 completion(...)
之前根据需要转换结果
我的文件 HealthStore
中有函数 calculateBloosPresureData
。我收到错误消息。
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)
}
}
你的补全签名不包含 HQSampleQuery
补全结果,所以只需更改它
func calculateBloosPresureData(completion: @escaping ([HKSample]?) -> Void) {
...
或在调用外部 completion(...)