Search code examples
swiftuiswiftui-navigationlinkswiftui-ontapgesture

Result of 'NavigationLink<Label, Destination>' initializer is unused


.toolbar(content: { ToolbarItem( placement: .topBarLeading, content: { NavigationLink( // Notes: destination: { ThirdSubView() }, label: { Image(systemName: "person") } ) } )

                    ToolbarItem(
                        placement: .topBarTrailing,
                        content: {
                            NavigationLink(
                                destination: {
                                    SecondSubView()
                                },
                                label: {
                                    Image(systemName: "gear")
                                }
                            )
                        }
                    )

                })

Solution

  • NavigationLink is a view. Don't use it in an closure. My suggestion should work, but could not test it because there are to many specific things in your example. Try to use code that works out of the box, so everybody can test.

    List {
        ForEach(listViewModel.items) { item in
            NavigationLink(
                destination: AddView(),
                label: {
                    ListRowView(item: item)
                        .onTapGesture (count:2){
                            withAnimation(.linear) {
                                listViewModel.updateItem(item: item)
                            }
                        }
                }
            )
        }
        .onDelete(perform: listViewModel.deleteItem)
        .onMove(perform: listViewModel.moveItem)
        
    }
    .listStyle(InsetListStyle())