KaasCoder
KaasCoder

Reputation: 251

How do I get the Severity value from a HKSample of the Health app

I want to show headache data from the Health app. From the HealtStore I get an array of [HKSamles]. How do I get the HKCategoryValueSeverity?

From each sample I can get the startDate, endDate, etc.

The sampleType is HKCategoryTypeIdentifierHeadache. At the moment I use the first character of the debugDescription of the HKSample as a Number for the HKCategoryValueSeverity.rawValue

I have this debugDescription for a HealthKit HKSample. So in the following description the severity rawValue is 4 -> .severe

4 1F6AED01-EB6A-4ADE-94C0-64F3F8B018BB " HKCategoryTypeIdentifierHeadache" (1), "iPhone13,3" (14.4) (2021-03-13 22:18:57 +0100 - 2021-03-13 22:28:57 +0100)

Upvotes: 0

Views: 375

Answers (1)

psolanki
psolanki

Reputation: 411

The sample you get the query is of type HKCategorySample which has a property value. See

https://developer.apple.com/documentation/healthkit/hkcategorysample?language=objc

For headache, like other symptom types, value is an enum of type HKCategoryValueSeverity

https://developer.apple.com/documentation/healthkit/hkcategorytypeidentifierheadache?language=objc https://developer.apple.com/documentation/healthkit/hkcategoryvalueseverity?language=objc

You can compare value to the list of possible enums to get severity.

Upvotes: 1

Related Questions