1

Basically I am trying to create a simple application with a list of items that can be clicked on to navigate to a detail view with an edit feature. The data is read from a JSON file which is why the data is in a binding so it can be updated and this is not a problem anywhere else in the project. I have tried rearranging the syntax of this ForEach loop but each time I'm presented with a different error.

import SwiftUI

struct EateryList: View {
    @Binding var eateries: [Eatery]
    var body: some View {
        NavigationView {
            VStack {
                List {
                        ForEach(eateries, id: \.self) { eatery in
                            NavigationLink(destination: EateryDetail(eatery: $eatery)) { //error
                               EateryRow(eatery: $eatery) //error
                           }
                        }
                }
                .navigationTitle("Favourite Eateries")
                .navigationBarItems(leading: EditButton(), trailing: Button( action: add)
                {
                    Image(systemName: "plus")
                    
                }
                    )
                     .listStyle(InsetGroupedListStyle())
            }
        }
        
    }
    func add() {
        eateries.append(Eatery(name: "Eatery", location: "Insert location here", notes: "Insert notes here", reviews: ["Insert reviews here"], url: "https://i.imgur.com/y3MMnba.png"))
    }
}

With the code above I get the errors in the line with NavigationLink and the line below too:

Cannot find '$eatery' in scope

Any help with this problem would be greatly appreciated :)

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
kmurp62rulz
  • 169
  • 2
  • 9

0 Answers0