The tutorial I had originally been following was taken down from YouTube so I had to a new one that would guide me through the process of accessing a user’s data from HealthKit. I found a tutorial about counting steps using HealthKit that took me just a few hours to complete.
One of the most important things I learned from this tutorial was how to generate a query using HKStatisticsCollection. The query takes a quantity type (this will be the type of metric I request from the user), a predicate (a time range to grab data from…this tutorial looks at the last seven days from the current date), and a few other things. I ideally want to grab data consistently so I’ll be looking into how to actively grab data (probably by having an app that can run in the background?).

The way the code comes together is pretty neat. Essentially there’s a struct “Step” that contains a UUID, step count, and date. In the ContentView file (what the user will see) we create a Step array called “steps” that saves Step instances when initialized. The “body” of the watch screen then gets a steps List and displays them in a VStack.
By connecting my phone to my laptop I was able to run the application on my watch. In order to access step count data I again had to request authorization from the user.

