Type of expression is ambiguous without more context

Hello, how can I get rid of this error ?

Type of expression is ambiguous without more context

 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)),

Answered by Claude31 in 691408022

This forum editor is really a mess. Recent messages disappear, then reappear when adding a phony new post, what I just do here !

Type of expression is ambiguous without more context

Unfortunately, your question is also ambiguous without more context.
Please can you post the whole code, not just a (cut-off) snippet?

The whole of the View body would be a good start...
...then indicate which expression is causing the error.

You should also consider answering (or closing) your other recent posts, where people have tried to help you:

If you are struggling to use the forum correctly, then ask for help with that... people will be happy to contribute.


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)

                }

                    ))}

    }

           }

                

What is this line ?

                NavigationLink(<Text>(VStack {

Is it really the code ? It is full of errors.

I've tried to change, guessing for some parts that were missing.

struct ContentView: View {
    @State var checknewHour: String = "0"
    @State var checknewMinute: String = "0"
    var body: some View {
        
        NavigationView {     // <<-- error was here ????
            Form {
                Group {
                    List {
                        VStack {
                            NavigationLink(destination: SomeOtherView()) {  // <<-- Need to specify this view
                                VStack {
                                    //     REMOVED -->>            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))
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Why have you such a complex struct (Form, Group, List …)

Here is what I get:

Is it what you expect ?

NavigationLink binds data from the widget to this page

Your code is not valid, as your brackets { } do not match up correctly.
Your struct "CalculatePaceView" is not a valid View, as it contains no "body".
(The "body" in your code sample is entirely outside the "CalculatePaceView" struct.)

I suggest you try separating out the View that you are using for the NavigationLink, and make it into a separate struct.
This should clarify what you are trying to achieve, and may make the error more obvious.

Deleted - needed empty message to address forum misbehaviour.

Yes, that's what I'm writing about, I want to link data from one page to another

PROBLEM was extra } before body statement.

I completed as this:

                                            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))
                                                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)
                                            }

And get:

So this at least works.

Yes, that's what I'm writing about, I want to link data from one page to another

  • link data: which date ? In what link ?
  • one page : which ?
  • another : which ?

Could you now explain precisely what you want to achieve, what is not working as expected ?

An error has occurred Failed to create diagnostics for an expression; please send us an error report.

Is a common error in my code.

I want calculatePace to move from this page with the navigation link, the data you showed me in the screenshot to the next page.

How to transfer this data from this struct with calculatePace navigation link to the next page ?

OK. Replace with this:

struct ContentView: View {
    @State var checknewHour: String = "0"
    @State var checknewMinute: String = "0"
    @State private var action: Int? = 0
    var body: some View {
        
        NavigationView {     // error is here
            Form {
                Group {
                    List {
                        VStack {
                            NavigationLink("", destination: OtherView(), tag: 1, selection: $action)
                            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))
                                            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)
                                                .onTapGesture {
                                                    self.action = 1
                                                }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

You can also replace the last Text by a button with a link. It is probably better.

struct ContentView: View {
    @State var checknewHour: String = "0"
    @State var checknewMinute: String = "0"
    //    @State private var action: Int? = 0
    
    var body: some View {
        
        NavigationView {     // error is here
            Form {
                Group {
                    List {
                        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))

                                        Button(action: {
                                        }, label: {
                                            NavigationLink(destination: OtherView()) {
                                                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)
                                            }
                                        })
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Have I to write another struct name ?

Accepted Answer

This forum editor is really a mess. Recent messages disappear, then reappear when adding a phony new post, what I just do here !

Type of expression is ambiguous without more context
 
 
Q