2026 SwiftUI & UI FrameworksHealth & Fitness
WWDC26 · 12 min · SwiftUI & UI Frameworks / Health & Fitness
Deliver workout insights with HealthKit workout zones
HealthKit makes it easier to provide workout insights — like heart rate and cycling power zones — in your app. Learn to leverage the built-in, personalized zones or create custom ones. Discover how to use the current zone and time spent in each zone to provide meaningful guidance during and after workouts.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 7 snippets
Reading Heart Rate Zones from a completed workout
// Read heart rate zones from the completed workout
if let heartRateZoneGroup = workout.zoneGroupsByType?[HKQuantityType(.heartRate)] {
let zones = ZoneDisplayData(
zoneCount: heartRateZoneGroup.configuration.zones.count,
currentZoneIndex: nil,
durations: heartRateZoneGroup.zoneDurations.map(\.duration)
) Handling Live Zone Updates
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder,
didUpdateWorkoutZone zoneUpdate: HKLiveWorkoutZoneUpdate) {
guard let zoneGroup = zoneUpdate.zoneGroup else {
return
}
if let currentIndex = zoneUpdate.currentZoneDuration?.zone.index {
let data = ZoneDisplayData(
zoneCount: zoneGroup.configuration.zones.count,
currentZoneIndex: currentIndex,
durations: zoneGroup.zoneDurations.map(\.duration)
)
Task { in
self.heartRateZones = data
}
}
} Check if Preferred Zone has been set
if try await builder.zoneConfiguration(for: HKQuantityType(.heartRate)) == nil { Create Zone Boundaries
let defaultHeartRateZoneThresholds = [91.0, 114.0, 136.0, 158.0]
let bpmUnit = HKUnit.count().unitDivided(by: HKUnit.minute())
let boundaries = defaultHeartRateZoneThresholds.map(
{HKQuantity(unit: bpmUnit, doubleValue:$0)}
) Create Default Workout Zone Configuration
let heartRate = HKQuantityType(.heartRate)
let defaultConfiguration = try HKWorkoutZoneConfiguration(quantityType: heartRate,
zoneBoundaries: boundaries) Set Custom Zone Configuration
try await builder.setCustomZoneConfiguration(defaultConfiguration,
for: heartRate)
} Begin Data Collection
// Begin data collection
let startDate = Date()
try await builder.beginCollection(at: startDate)