1
AppleのHealthKitを使用するSwift 4.0のアプリケーションで作業しています。私は、アプリケーションがHealthKitからユーザーの手順を取得している。ここに私の作業コードがあります:HealthKit HKStatisticsQueryのエラーとして「式の種類が曖昧です」
//sampleType declaration
let sampleType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
//define the predicate from the passed start and end times
let queryPredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: .strictStartDate)
//build the query
let cumulativeSumQuery = HKStatisticsQuery(quantityType: sampleType!, quantitySamplePredicate: queryPredicate, options: .cumulativeSum, completionHandler: { (cumulativeSumQuery, results, error) in
//PROCESS THE DATA//
})
//execute the query
self.healthStore.execute(cumulativeSumQuery)
問題は、複数のソースからデータが必要です。だから、私はHKStatisticsのオプションとして.separateBySourceを追加したいと思います。 this questionとthe Apple documentationに基づいて、次のコードは、単に私のoptions:
//sampleType declaration
let sampleType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)
//define the predicate from the passed start and end times
let queryPredicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: .strictStartDate)
//build the query
let cumulativeSumQuery = HKStatisticsQuery(quantityType: sampleType!, quantitySamplePredicate: queryPredicate, options: .cumulativeSum | .separateBySource, completionHandler: { (cumulativeSumQuery, results, error) in
//PROCESS THE DATA//
})
//execute the query
self.healthStore.execute(cumulativeSumQuery)
に| .separateBySource
を追加することで作業が必要がありますが、その代わり、私はエラーType of expression is ambiguous without more context
を取得します。 Xcode赤は、私の2つのオプションの間に|
文字の下線を引いています。 SWIFT 4.0の場合