问题
I have a issue I'm trying to resolve at Calculate Asleep time in HealthKit using Swift. It is regarding only summing the .asleep values with my query. Through my research, I believe the solution resides in a predicate that filters this value. Then, I can use NSCompoundPredicate to merge the predicates together for my query. I just don't know how to reach it. Here is the predicate line I'm trying to use:
let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: .strictStartDate)
let asleepPredicate = HKQuery.predicateForObjects(from: HKObjectType.categoryType(forIdentifier: HKCategoryValueSleepAnalysis.asleep))
let queryPredicate = NSCompoundPredicate(notPredicateWithSubpredicate: predicate, asleepPredicate)
I get the following error:
Cannot convert value of type 'HKCategoryValueSleepAnalysis' to expected argument type 'HKCategoryTypeIdentifier'
I know that I am close to resolving this issue and any guidance provided is greatly appreciated.
来源:https://stackoverflow.com/questions/61272231/predicate-to-filter-asleep-from-sleepanalysis