Earliest sample dates in HealthKit

When building a watchOS extension for my iPhone app Personal Best, I couldn’t figure out why querying the HealthKit store for workouts was only returning 25 results, as opposed to over 700 on iPhone.

It turns out that iOS and watchOS have separate HealthKit stores. watchOS only stores seven days worth of workouts.

You can confirm this by using HKHealthStore’s earliestPermittedSampleDate method:

let healthStore = HKHealthStore()

// When called on iOS:
healthStore.earliestPermittedSampleDate() // 0001-01-01 00:00:00 +0000

// When called on watchOS:
healthStore.earliestPermittedSampleDate() // 2020-05-25 23:00:00 +0000

Thanks for reading.

To get in touch, email me or find me on Mastodon or Twitter.

If you liked this post, you'll love my iOS apps. Check out 🥇 Personal Best, 🎵 Taylor's Version, and 🐷 SalaryPig.