What you need to do is create a computed variable that calculates the speed using the three picker values and your formula.
Here's an example of what that would look like:
struct ContentView: View {
@State var secondesSelection = 10
@State var dixiemesSelection = 0
@State var pisteSelection = 200
let secondes = Array(10..<60)
let dixiemes = Array(0..<10)
let longueurPiste = [200, 250, 333, 500]
// Create computed variable that calculates the speed (in km/h)
var vitesseCalculee: Double {
let tempsTour = Double(secondesSelection) + (Double(dixiemesSelection) / 10)
return (Double(pisteSelection) / 1000) / (tempsTour / 3600)
}
// Nicely format that speed (rounding to 3 s.f.)
var formattedVitesseCalculee: String {
"\(vitesseCalculee.formatted(.number.precision(.significantDigits(3)))) km/h"
}
var body: some View {
VStack {
Label("Calcul du temps au tour", systemImage: "stopwatch")
Spacer()
Text("Longueur de la piste")
.font(.title.bold())
.foregroundColor(.blue)
Picker("Longueur de la piste", selection: $pisteSelection) {
ForEach(longueurPiste, id: \.self) {
Text("\($0) m")
}
}
.pickerStyle(.wheel)
Text("Temps au tour")
.font(.title.bold())
.foregroundColor(.blue)
HStack {
Text("Secondes")
Text("Dixièmes")
}
HStack {
Picker("Secondes", selection: $secondesSelection) {
ForEach(secondes, id: \.self) {
Text("\($0)'")
}
}
Picker("Dixièmes", selection: $dixiemesSelection) {
ForEach(dixiemes, id: \.self) {
Text("\($0)")
}
}
}
.pickerStyle(.wheel)
Spacer()
Text("Vitesse calculée: \(formattedVitesseCalculee)")
.font(.largeTitle)
.foregroundColor(.blue)
}
}
}
Your program had a few warnings when I pasted your code in so I resolved them.