Type identifiers used for tracking diet and nutrition.
Nutritional data can be broadly categorized into two main groups:
Macronutrients representing fats, carbohydrates, and proteins, which are consumed in large quantities and provide energy.
Micronutrients represent vitamins and minerals which are required by the body, but are consumed in much smaller quantities.
HealthKit also provides type identifiers for nutrition-related items that users may want to track: for example, tracking the amount of water the user drinks, or the amount of caffein they consume.
You do not need to track all nutritional information. Instead, you can focus just on the items of interest to your users. In general, the data from nutrition labels is a good place to start. Many countries require a nutrition label on packaged food. While the contents of these labels vary from country to country, they typically include:
Working with Hierarchical Sample Types
The Macronutrient identifiers can be thought of as a hierarchy. The
dietary identifier represents the total amount of energy from all fats, carbohydrates, and protein. You can provide a more-detailed breakdown using the
dietary identifiers. Fats and carbohydrates can further separated into even smaller categories (
dietary for fat.
dietary for carbohydrates.).
Unless your app is very focused (for example tracking only sugar or saturated fat), always provide the total data (
dietary), and then optionally provide the more detailed information using the subcategories. You do not need to provide data for all of the subcategories; however, the sum of the subcategory sample values should be equal or less than the total sample’s value.