Hello, I'm new to SwiftUI programming. I am looking to do a calculation from 3 Picker (wheel). In the first I have to retrieve a track length in meters. In the second and the third I recover 2 values which associated make seconds and tenths (lap time). The calculation I want to perform = (length / 1000) / ( lap time (in seconds and tenths) / 3600)
thank you in advance for your help
// Created by Thierry Lebeau on 24/11/2022.
//
import SwiftUI
struct ContentView: View {
@State var secondeSelection = 0
@State var dixiemeSelection = 0
@State var pisteSelection = 0
var secondes = [Int](10..<60)
var dixiemes = [Int](0..<10)
let longueurPiste = [200, 250, 333, 500]
var vitesseCalculee = Double()
var body: some View {
VStack {
Label("Calcul du temps au tour", systemImage: "stopwatch")
Spacer()
Text("Longueur de la piste")
.font(.title)
.fontWeight(.semibold)
.foregroundColor(Color.blue)
Picker(selection: self.$pisteSelection, label: Text("")){
ForEach(0 ..< longueurPiste.count){ index in
Text("\(self.longueurPiste[index]) m").tag(index)
}
}
.pickerStyle(WheelPickerStyle())
// Spacer()
Text("Temps au tour")
.font(.title)
.fontWeight(.semibold)
.foregroundColor(Color.blue)
HStack{
Text("Secondes")
Text("Dixièmes")
}
HStack {
Picker(selection: self.$secondeSelection, label: Text("")){
ForEach(0 ..< self.secondes.count){ index in
Text("\(self.secondes[index])'").tag(index)
}
}
.pickerStyle(WheelPickerStyle())
Picker(selection: self.$dixiemeSelection, label: Text("")){
ForEach(0 ..< self.dixiemes.count){ index in
Text("\(self.dixiemes[index])").tag(index)
}
}
.pickerStyle(WheelPickerStyle())
}
Spacer()
Text("Vitesse calculée: \(secondes[secondeSelection])'\(dixiemes[dixiemeSelection])")
.font(.largeTitle)
.fontWeight(.regular)
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
}
Spacer()
// .background(.cyan)
}
}
// vitesseCalculee = (longueurPiste/1000) / (tempsTour/3600)
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}