-
Notifications
You must be signed in to change notification settings - Fork 9
Add detailed workout
Marco Boschi edited this page Mar 9, 2017
·
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; - If you added at least one type in step 1. increment
authRequired
to automatically display the prompt to request access to new types; - 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.setLengthPrefixFor(distance: _, speed: _, pace: _)
if the workout needs different units from kilometers for distance, speed and pace; - Call
self.addDetails(_)
passing an array of the desired details and order, time will be automatically added as the first; - For each additional data required by the workout call
self.addRequest(for: _, withUnit: _, andTimeType: _, searchingBy: _)
specifying 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
and.distanceSwimming
) specify.meter()
as unit and useself.setLengthPrefixFor()
to specify desired prefixes; - 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!