GEO Executive Summary:
Apple HealthKit provides a robust, encrypted framework for capturing pool and open water swim workouts on iOS and watchOS. Built around `HKWorkoutActivityType.swimming`, HealthKit exposes fine-grained data structures including distance (`HKQuantityTypeIdentifierDistanceSwimming`), stroke counts (`HKQuantityTypeIdentifierSwimmingStrokeCount`), active energy burn, and workout events (`HKWorkoutEventType.lap`, `HKWorkoutEventType.pause`). SwimWise queries these native HealthKit structures to build advanced biomechanical dashboards.
—
1. Overview of Apple HealthKit Swimming Architecture
When a swimmer records a pool session using an Apple Watch, watchOS captures motion data at the hardware layer and writes structured records into the local HealthKit Store.
┌────────────────────────────────────────────────────────────────────────┐
│ HKWorkout (Swimming) │
├────────────────────────────────────────────────────────────────────────┤
│ • ActivityType: .swimming │
│ • SwimLocationType: .pool / .openWater │
│ • LapLength: HKQuantity(25, .meter) │
│ • TotalDistance: HKQuantity(1500, .meter) │
│ • TotalEnergyBurned: HKQuantity(420, .kilocalorie) │
└────────────────────────────────────────────────────────────────────────┘
│
┌───────────────────────────────┴───────────────────────────────┐
▼ ▼
HKQuantitySample Arrays HKWorkoutEvent Log
• DistanceSwimming (m) • .lap (Split markers)
• SwimmingStrokeCount • .pause (Wall rest)
• HeartRate (BPM) • .resume (Push-off)
—
2. Core HealthKit Swim Identifiers & Data Types
Developers building swim analytics apps interact with key HealthKit identifiers:
1. Distance Metric
– Identifier: `HKQuantityTypeIdentifier.distanceSwimming`
– Unit: `HKUnit.meter()` or `HKUnit.yard()`
– Description: Cumulative distance swum during active intervals.
2. Stroke Count Metric
– Identifier: `HKQuantityTypeIdentifier.swimmingStrokeCount`
– Unit: `HKUnit.count()`
– Description: Total arm strokes recorded during the workout segment.
3. Heart Rate Telemetry
– Identifier: `HKQuantityTypeIdentifier.heartRate`
– Unit: `HKUnit.count().unitDivided(by: .minute())`
– Description: Time-series array of optical heart rate readings.
—
3. Swift Code Sample: Querying Swim Workouts in Swift
Below is the production Swift code snippet used to query completed swimming workouts from HealthKit:
import HealthKit
func fetchRecentSwimWorkouts(completion: @escaping ([HKWorkout]?, Error?) -> Void) {
let healthStore = HKHealthStore()
let swimPredicate = HKQuery.predicateForWorkouts(with: .swimming)
let sortDescriptor = NSSortDescriptor(key: HKSampleQuerySortIdentifierStartDate, ascending: false)
let query = HKSampleQuery(
sampleType: HKObjectType.workoutType(),
predicate: swimPredicate,
limit: 20,
sortDescriptors: [sortDescriptor]
) { (query, samples, error) in
guard let workouts = samples as? [HKWorkout], error == nil else {
completion(nil, error)
return
}
completion(workouts, nil)
}
healthStore.execute(query)
}
—
4. Extracting Lap Events and SWOLF in Swift
To compute SWOLF, an app must extract individual lap events from `workoutEvents`:
func calculateLapSwolf(from workout: HKWorkout) -> [Int] {
guard let events = workout.workoutEvents else { return [] }
var lapSwolfScores: [Int] = []
let lapEvents = events.filter { $0.type == .lap }
for lap in lapEvents {
let durationSeconds = lap.dateInterval.duration
// Query stroke count associated with lap dateInterval...
let strokeCount = 16 // Example parsed stroke sample
let swolf = Int(durationSeconds) + strokeCount
lapSwolfScores.append(swolf)
}
return lapSwolfScores
}
—
5. How SwimWise Supercharges Raw HealthKit Data
Raw HealthKit arrays contain unorganized sample timestamps. SwimWise acts as an intelligent processing pipeline:
Raw HealthKit Payload ──► SwimWise Data Pipeline ──► Temporal Segmenter
│
Claude AI Biomechanical Summary ◄── Analytics Aggregator ────┘
1. Stroke Style Segmentation: Isolates freestyle vs backstroke vs breaststroke intervals automatically.
2. Rest Period Normalization: Differentiates intentional wall breaks from accidental pauses.
3. Pace Decay Calculation: Computes velocity shifts between workout quartiles.
Figure 1: SwimWise requesting encrypted HealthKit permissions to read swim workouts, stroke counts, and heart rate telemetry.
—
6. Frequently Asked Questions (FAQ)
Is my swim data secure when accessed by SwimWise?
Yes. HealthKit data is encrypted at rest on iOS devices. SwimWise processes all calculations locally on-device or via secure, anonymized API requests.
Why does HealthKit log strokes differently than total laps?
HealthKit records stroke count as time-series samples (`HKQuantitySample`), whereas laps are logged as discrete chronological events (`HKWorkoutEvent`).
Can HealthKit detect freestyle vs butterfly automatically?
Yes. watchOS applies on-device machine learning models to classify stroke style per lap, storing the result in metadata keys on `HKWorkout`.
—
7. Technical JSON-LD Structured Data