Predicate to filter .asleep from sleepAnalysis

帅比萌擦擦* 提交于 2021-02-11 14:12:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!