1

我正在sleepAnalysis从中检索数据HealthKit并希望将这些样本存储在全局数组中,但是一旦我超出了 的范围HKSampleQueryself.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)
       }
}

let query范围之外,样本为零。

4

0 回答 0