我正在从sleepAnalysis
检索HealthKit
数据,并希望将这些样本存储在全局数组中,但一旦我超出HKSampleQuery
的范围,{ {1}}回到它的空数组的初始值。如何在查询范围之外检索这些值?
self.globalVariable
在if let sleepType = HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis) {
let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)
let query = HKSampleQuery(sampleType: sleepType, predicate: nil,limit: 90, sortDescriptors: [sortDescriptor]) { (query, tmpResult, error)-> Void in
if error != nil {
return
}
if let result = tmpResult {
for item in result {
if let sample = item as? HKCategorySample {
samples.append(sample)
}
}
}
healthStore.execute(query)
}
}
范围之外,样本为零。