Post

Replies

Boosts

Views

Activity

Reply to Calculation for a Picker
Hello, I come back for a problem encountered on another View. The result of my calculation is not exact because I think that the value retrieved in the Picker does not include tenths, but above all the variation of the Slider TpsFirstTour has no effect on the result. Do you see where it comes from? Thanks in advance     @State var minutesSelection = 18     @State var secondesSelection = 0     @State private var valeurSliderNbreTour = 14.0     @State private var valeurSliderTpsFirstTour = 20.0          let minutes = Array(1..<6)     let secondes = Array(0..<60)          // Creation de la variable tps au tour     var tpsauTour: Double {         let tpspoursuite = Double(minutesSelection) + (Double(secondesSelection))         return (((Double(tpspoursuite) * 3600) - valeurSliderTpsFirstTour )/(valeurSliderNbreTour - 1))     }     // Format du tps au tour     var formattedtpsauTour: String {         "\(tpsauTour.formatted(.number.precision(.significantDigits(3)))) s"     }          var body: some View {         VStack {             Text("Temps total de la poursuite")                 .font(.title.bold())                 .foregroundColor(.blue)             HStack( spacing : 120.0) {                                 Text("Minutes")                 Text("Secondes")                           }             HStack {                 Picker("Minutes", selection: $minutesSelection) {                     ForEach(minutes, id: \.self) {                         Text("\($0)'")                     }                 }                 Picker("Secondes", selection: $secondesSelection) {                     ForEach(secondes, id: \.self) {                         Text("\($0)")                     }                 }             }             .pickerStyle(.wheel)                          Text("Temps du premier tour")                 .font(.title.bold())                 .foregroundColor(.blue)                          Slider(value: $valeurSliderTpsFirstTour, in: 15...25, step: 0.1) {             } minimumValueLabel: {                 Text("15.0")             } maximumValueLabel: {                 Text("25.0")             }             Text(valeurSliderTpsFirstTour.description)                 .font(.largeTitle)                          Text("Nombre de tours")                 .font(.title.bold())                 .foregroundColor(.blue)                          Slider(value: $valeurSliderNbreTour, in: 8...20, step: 1.0) {             } minimumValueLabel: {                 Text("8")             } maximumValueLabel: {                 Text("20")             }             Text(Int(valeurSliderNbreTour).description)                 .font(.largeTitle)                          Text("Temps au tour: \(formattedtpsauTour)")                       .font(.title.bold())                       .foregroundColor(.blue)             }                  }     }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to Calculation for a Picker
Hello, I come back for a problem encountered on another View. The result of my calculation is not exact because I think that the value retrieved in the Picker does not include tenths, but above all the variation of the Slider TpsFirstTour has no effect on the result. Do you see where it comes from? Thanks in advance     @State var minutesSelection = 18     @State var secondesSelection = 0     @State private var valeurSliderNbreTour = 14.0     @State private var valeurSliderTpsFirstTour = 20.0          let minutes = Array(1..<6)     let secondes = Array(0..<60)          // Creation de la variable tps au tour     var tpsauTour: Double {         let tpspoursuite = Double(minutesSelection) + (Double(secondesSelection))         return (((Double(tpspoursuite) * 3600) - valeurSliderTpsFirstTour )/(valeurSliderNbreTour - 1))     }     // Format du tps au tour     var formattedtpsauTour: String {         "\(tpsauTour.formatted(.number.precision(.significantDigits(3)))) s"     }          var body: some View {         VStack {             Text("Temps total de la poursuite")                 .font(.title.bold())                 .foregroundColor(.blue)             HStack( spacing : 120.0) {                                 Text("Minutes")                 Text("Secondes")                           }             HStack {                 Picker("Minutes", selection: $minutesSelection) {                     ForEach(minutes, id: \.self) {                         Text("\($0)'")                     }                 }                 Picker("Secondes", selection: $secondesSelection) {                     ForEach(secondes, id: \.self) {                         Text("\($0)")                     }                 }             }             .pickerStyle(.wheel)                          Text("Temps du premier tour")                 .font(.title.bold())                 .foregroundColor(.blue)                          Slider(value: $valeurSliderTpsFirstTour, in: 15...25, step: 0.1) {             } minimumValueLabel: {                 Text("15.0")             } maximumValueLabel: {                 Text("25.0")             }             Text(valeurSliderTpsFirstTour.description)                 .font(.largeTitle)                          Text("Nombre de tours")                 .font(.title.bold())                 .foregroundColor(.blue)                          Slider(value: $valeurSliderNbreTour, in: 8...20, step: 1.0) {             } minimumValueLabel: {                 Text("8")             } maximumValueLabel: {                 Text("20")             }             Text(Int(valeurSliderNbreTour).description)                 .font(.largeTitle)                          Text("Temps au tour: \(formattedtpsauTour)")                       .font(.title.bold())                       .foregroundColor(.blue)             }                  }     }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Calculation for a Picker
Hello, Thank you very much, it works perfectly. I will continue on the following views and there is a very good chance that I will come back to ask some questions. Thanks again
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22