duration(for:)
Returns the total duration covering all the samples created by the specified source that also match the query.
Declaration
func duration(for source: HKSource) -> HKQuantity?Discussion
If you set both the duration and separateBySource options, this method returns a quantity object. This object contains the total duration covering all the samples created by the specified source that also match the query. If the statistics options were not both set, this method returns nil.