Skip to content

Add detailed workout

Marco Boschi edited this page Mar 24, 2019 · 10 revisions

In order to add support to details to a new workout type follow these steps:

  1. In Main.swift add additional HKObjectTypes to healthReadData as appropriate,
    • Note: if you're adding a new distance type beside currently supported ones modify WorkoutMinute.rawDistance to make it aware of this by trying to load the new distance type after (or before if appropriate) current ones.
  2. If currently supported details are not enough for the new workout add a new detail as a static constant in the WorkoutDetail class to express which data to display and how both inside the app and in the CSV file when exporting.
  3. Create a custom subclass of Workout for the new workout type and override init(_, delegate: _), after invoking super.init(_, delegate: _):
    1. Call self.setLengthUnitsFor(distance: _, speed: _, pace: _) if the workout needs different units from kilometers/miles for distance, speed and pace.
    2. Call self.set(maxPace: _), if the workout is distance-based, to set the maximum valid pace in seconds per kilometer, bigger values will not be considered relevant because they're too big. If pace is not relevant at all for the workout skip this step or pass nil.
    3. If a minute-by-minute breakdown of the workout is appropriate construct a new instance of MinuteByMinuteBreakdown by passing an array of the desired details and order, time will be automatically added as the first. Add it to the workout using self.addAdditionalDataProcessorsAndProviders(_)
    4. For each additional data required by the workout call self.addQuery(_) by passing an instance of WorkoutDataQuery that specifies which data to load and its unit, whether to treat the data as single point in time, i.e. heart rate, or a value for a certain duration, i.e. distance, and how to query for the data, by time of the workout or only data explicitly linked to the workout.
      • Note: when loading distance data (.distanceWalkingRunning, .distanceSwimming or others) specify WorkoutUnit.meter as unit and use self.setLengthUnitsFor() to specify desired display units;
  4. Update the factory method Workout.workoutFor(raw: _, delegate: _) with a case for the new workout, note that a single class can be used to handle multiple workout types.
  5. Enjoy!
Clone this wiki locally