Have I to write another struct name ?
Post
Replies
Boosts
Views
Activity
How to transfer this data from this struct with calculatePace navigation link to the next page ?
I want calculatePace to move from this page with the navigation link, the data you showed me in the screenshot to the next page.
An error has occurred Failed to create diagnostics for an expression; please send us an error report.
Is a common error in my code.
Yes, that's what I'm writing about, I want to link data from one page to another
NavigationLink binds data from the widget to this page
struct CalculatePaceView: View {
@State private var checknewTime = ""
@State private var checknewHour = ""
@State private var checknewMinute = ""
@State private var checknewSeconds = ""
@State private var checknewDistance = ""
@State private var checknewMeters = ""
@State private var checknewKilometers = ""
@State private var checknewMiles = ""
@State private var checknewYards = ""
@State private var checknewPace = ""
@State private var checkperMeter = ""
@State private var checkperKilometer = ""
@State private var checkperMile = ""
@State private var checkperYard = ""
var calculatePace: Double {
guard let newDistance = Double(checknewDistance),
let newTime = Double(checknewTime),
let newMeters = Double(checknewMeters),
let newKilometers = Double(checknewDistance),
let newMiles = Double(checknewMiles),
let newYards = Double(checknewYards),
// let newPace = Double(checknewPace),
let newHour = Double(checknewHour),
let newMinute = Double(checknewMinute),
let newSeconds = Double(checknewSeconds),
let perMeter = Double(checkperMeter),
let perKilometer = Double(checkperKilometer),
let perMile = Double(checkperMile),
let perYard = Double(checkperYard)
else {
return 0
}
let NewTime = [newHour, newMinute, newSeconds]
let NewHour = newHour
let NewMinute = newMinute
let NewSeconds = newSeconds
let NewDistance = newDistance
let NewMeter = newMeters
let NewKilometer = newKilometers
let NewMiles = newMiles
let NewYards = newYards
let NewPace = [perMeter, perKilometer, perMile, perYard]
let calculatePace = (Double(NewTime[0]*3600 + NewTime[1]*60 + NewTime[2]) / Double(3600 * NewDistance))
return calculatePace
}
}
var body: some View {
NavigationView { // error is here
Form {
Group {
List {
VStack {
NavigationLink(<Text>(VStack {
ScrollView(.vertical) {
VStack(spacing: 13) {
ForEach(0..<1) {_ in TextField("Enter hour",text:$checknewHour
.keyboardType(.decimalPad)
.font(.system(size: 25)), Text("\(checknewHour) $ Hour")
.foregroundColor(.purple)
.font(.system(size: 25)),TextField("Enter minute",text:$checknewMinute
.keyboardType(.decimalPad)
.font(.system(size: 25)), Text("\(checknewMinute) $ Minute")
.foregroundColor(.purple)
.font(.system(size: 25)), label: {
Text("Calculate Pace")
.bold()
.frame(width: 280, height: 50)
.background(Color.init(red: 0.818, green: 0.688, blue: 0.095))
.foregroundColor(.white)
.cornerRadius(10)
.navigationTitle ("Pace Calculator")
// .navigationBarTitleDisplayMode(.inline)
.padding(5)
}
))}
}
}
Thank you very much, I corrected the code and the error disappeared.
let NewTime = [newHour, newMinute, newSeconds]
let NewHour = newHour
let NewMinute = newMinute
let NewSeconds = newSeconds
let NewDistance = newDistance
let NewMeter = newMeters
let NewKilometer = newKilometers
let NewMiles = newMiles
let NewYards = newYards
let NewPace = [perMeter, perKilometer, perMile, perYard]
let calculatePace = (NewTime / NewDistance)
return calculatePace
}
}
Sorry, but unfortunately the conversion of Int values to Double values failed. How to convert the values in the Int array into Double values so that the two values are divided by each other ?
Thank you, I know how to solve.
The body is already defined,
Can you give me an example of an argument ?
After correcting the error, this error appeared:
Cannot find '$contentData' in scope
Again, the error appears :
Closure containing a declaration cannot be used with result builder 'ViewBuilder' :
struct ContentView_Previews: PreviewProvider { // <- error Closure containing a declaration cannot be used with result builder 'ViewBuilder' and Struct 'ViewBuilder' declared here (SwiftUI.ViewBuilder)
static var previews: some View {
ContentView()
}
}
static var previews: some View {
ContentView()
}
}