Conflicting arguments to generic parameter 'Content' on NavigationLink for @Binding var

Hi !

I am having a very strange problem. I display a list of elements, and I created a view that takes this element as a parameter in order to allow the user to modify it in another view.

my var with a forEach :

@Binding var liste : Liste

my code :

ScrollView {
  LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 5) {
    ForEach(liste.cartes) { c in
      NavigationLink(destination: ModifierUneCarte(carte: c)) {
        VStack {
          Text(c.devant)
            .font(.system(size: 14))
          Divider()
          Text(c.derriere)
            .font(.system(size: 14))
        }
      }
    }
  }
}

and my ModifierUneCarte :

struct ModifierUneCarte: View {
    
  [...]
    @Binding var carte: Carte
  [...]

And I have this error on a lot of lines :

Conflicting arguments to generic parameter 'Content' ('<<hole>>' vs. '<<hole>>' vs. '<<hole>>' vs. '<<hole>>')

but it's because of :

NavigationLink(destination: EditMap(map: c)) {

because when I remove it everything works...

Answered by Claude31 in 750818022

J'ai modifié comme suit:

        ScrollView {
            LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 5) {
                ForEach($liste.cartes) { $c in
                    NavigationLink(destination: ModifierUneCarte(carte: $c)) {

Dans le simulator:

Note: le preview en revanche n'affiche pas la liste..

Isn't the error coming from line 44 .navigationBarItem ?

Could you post the complete code so we can test ?

import SwiftUI

struct AfficherUneListe: View {
    
    @Binding var liste : Liste
    @Binding var showNavigationBar: Bool
    
    var body: some View {
        
        Spacer()
        Text("Les cartes")
            .font(.headline)
        ScrollView {
            LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 5) {
                ForEach(liste.cartes) { c in
                    NavigationLink(destination: ModifierUneCarte(carte: c)) {
                        VStack {
                            RoundedRectangle(cornerRadius: 10)
                                .foregroundColor(.white)
                                .shadow(radius: 3)
                                .padding(5) &#x2F;&#x2F; Ajouter un padding supplémentaire
                                .overlay(
                                    VStack {
                                        Text(c.devant)
                                            .font(.system(size: 14))
                                        Divider()
                                        Text(c.derriere)
                                            .font(.system(size: 14))
                                    }
                                )
                        }
                        .frame(width: 100, height: 100)
                    }
                }
            }
        }
        .navigationBarItems(trailing: HStack {
                   Button(action: {
                       &#x2F;&#x2F; Code pour le premier bouton
                   }) {
                       Image(systemName: "play")
                   }
                   
                   Button(action: {
                       &#x2F;&#x2F; Code pour le deuxième bouton
                   }) {
                       Image(systemName: "trash")
                   }
               })
               .navigationTitle(liste.nom)
    }
}


struct AfficherUneListe_Previews: PreviewProvider {
    static var previews: some View {
        let liste = Liste(nom: "Liste 1", cartes: [
            Carte(devant: "Avant 1-1", derriere: "Derriere 1-1", dateProchaineRevision: Date()),
            Carte(devant: "Avant 1-2", derriere: "Derriere 1-2", dateProchaineRevision: Date()),
            Carte(devant: "Avant 1-3", derriere: "Derriere 1-3", dateProchaineRevision: Date())
        ])
        return NavigationView {
            AfficherUneListe(liste: Binding.constant(liste), showNavigationBar: Binding.constant(false))
        }
    }
}
import SwiftUI

struct ModifierUneCarte: View {
    
    @State private var avant = ""
    @State private var arriere = ""
    @Binding var carte: Carte
    
    var body: some View {
        
        
        VStack {
            TextEditor(text: $avant)
                .frame(height: 200)
                .padding()
                .background(
                    RoundedRectangle(cornerRadius: 10)
                        .stroke(Color.blue, lineWidth: 2)
                )
                .padding()
            
            TextEditor(text: $arriere)
                .frame(height: 200)
                .padding()
                .background(
                    RoundedRectangle(cornerRadius: 10)
                        .stroke(Color.blue, lineWidth: 2)
                )
                .padding()
            
            Button(action: {

                carte.devant = avant;
                carte.derriere = arriere;
                
                avant = ""
                arriere = ""
            }) {
                Text("Ajouter la carte")
                    .fontWeight(.bold)
                    .font(.system(size: 20))
                    .foregroundColor(.white)
                    .padding()
                    .background(
                        RoundedRectangle(cornerRadius: 10)
                            .stroke(Color.blue, lineWidth: 2)
                            .background(
                                RoundedRectangle(cornerRadius: 10)
                                    .fill(Color.blue)
                            )
                    )
            }
            Spacer()
        }
        .navigationTitle("Modifier une carte")
    }
}


struct ModifierUneCarte_Previews: PreviewProvider {
static var previews: some View {
    ModifierUneCarte(carte: .constant(Carte(devant: "Devant", derriere: "Derriere", dateProchaineRevision: Date())))
}
}

And structs :

Thanks

Accepted Answer

J'ai modifié comme suit:

        ScrollView {
            LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))], spacing: 5) {
                ForEach($liste.cartes) { $c in
                    NavigationLink(destination: ModifierUneCarte(carte: $c)) {

Dans le simulator:

Note: le preview en revanche n'affiche pas la liste..

thank you so much Claude31. You saved many days of mine. My case was this: when I was having destination as simple Text it was working without $ sign everywhere. But when I set the destination to a custom view which has a binding variable, I needed $ as mentioned by you.

NavigationSplitView {
            List {
                ForEach($topics, id: \.self) { $topic in
                    NavigationLink(destination:BeginQuizView(topic:$topic)) {
                    //NavigationLink(destination:Text(topic.title)) {
Conflicting arguments to generic parameter 'Content' on NavigationLink for @Binding var
 
 
Q