Many apps use charts to represent data to the user. This is especially so for apps such as weight tracking, step counting, and anything else that is HealthKit related. Thankfully, Apple has created the Swift Charts framework to help you build these charts.
In today’s tutorial, we’ll look at extracting step count data from HealthKit and representing that in a chart within a SwiftUI application. We will have two charts, the first being a bar chart showing today’s step counts broken into hours and the second showing daily step counts for the last thirty days.
This tutorial will cover fetching information from HealthKit, processing that data and formatting it to make it easier to pass values to the charts framework. It will cover creating the views and the prompt needed to grant the necessary permissions.
[Read more…]