我正在尝试使用以下代码从香港心电图中检索所有症状:
func getAllSymptoms(from sample: HKElectrocardiogram) {
let catIds: [HKCategoryTypeIdentifier] = [
.rapidPoundingOrFlutteringHeartbeat,
.skippedHeartbeat,
.fatigue,
.shortnessOfBreath,
.chestTightnessOrPain,
.fainting,
.dizziness,
]
for catId in catIds {
getSymptoms(from: sample, categoryType: catId) {
(cat: HKCategoryTypeIdentifier, userEntered: Bool) in
print("\(cat) entered: \(userEntered)")
}
}
}
func getSymptoms(from sample: HKElectrocardiogram,
categoryType: HKCategoryTypeIdentifier,
completion: @escaping (HKCategoryTypeIdentifier, Bool)->Void){
guard sample.symptomsStatus == .present,
let sampleType = HKSampleType.categoryType(forIdentifier: categoryType) else {
completion(categoryType, false)
return
}
let predicate = HKQuery.predicateForObjectsAssociated(electrocardiogram: sample)
let sampleQuery = HKSampleQuery(
sampleType: sampleType,
predicate: predicate,
limit: HKObjectQueryNoLimit, …Run Code Online (Sandbox Code Playgroud)