-
Notifications
You must be signed in to change notification settings - Fork 9
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:
- In
Main.swift
add additionalHKObjectType
s tohealthReadData
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.
-
Note: if you're adding a new distance type beside currently supported ones modify
- 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. - Create a custom subclass of
Workout
for the new workout type and overrideinit(_, delegate: _)
, after invokingsuper.init(_, delegate: _)
:- Call
self.setLengthUnitsFor(distance: _, speed: _, pace: _)
if the workout needs different units from kilometers/miles for distance, speed and pace. - 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 passnil
. - 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 usingself.addAdditionalDataProcessorsAndProviders(_)
- For each additional data required by the workout call
self.addQuery(_)
by passing an instance ofWorkoutDataQuery
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) specifyWorkoutUnit.meter
as unit and useself.setLengthUnitsFor()
to specify desired display units;
-
Note: when loading distance data (
- Call
- 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. - Enjoy!