First of all, I have read through some of "similar" enquiry, but none seem to specifically describe the issue I encountered. Most are Swift 3 and earlier, which I am currently unable to comprehend. Please pardon my small request to sought for some help here.
struct Workout {
var distance: Double
var time: Double
var averageHR: Int
}
extension Workout: CustomStringConvertible {
var description: String {
return "\(distance) metres at \(time) seconds with HR \(averageHR)"
}
}
extension Workout {
static var speed: Double {
return distance / time
}
func harderWorkout() -> Workout {
let newDist = distance * 2
let newTime = time * 2
let newAverageHR = averageHR + 40
return Workout(distance: newDist, time: newTime, averageHR: newAverageHR)
}
}
The question asked in the tutorial is "Now create another extension for Workout and add a property speed of type Double. It should be a computed property that returns the average meters per second traveled during the workout."
And that's where I'm stuck, to specifically go according to the instructions given. The best I can do is to create a workaround using a static func instead
static func calculateSpeed(distance: Double, time: Double) -> Double {
var speed: Double { return distance / time }
return speed
}
But it seem forced. Would anyone know what would be the "correct" way to actually solve this? I think is more of how to compute the properties within the structure, which I am unable to recall or search for any answers. I really appreciate any help rendered.