xcodeswiftui

Why is my navigationlink not working. I get this error : "Result of 'NavigationLink<Label, Destination>' initializer is unused"


var body: some View {
    NavigationView
    {
        ScrollView
        {
            LazyVGrid(columns: [
                        GridItem(.flexible(minimum: 100, maximum: 200), spacing: 16, alignment: .top),
                        GridItem(.flexible(minimum: 100, maximum: 200), spacing: 16, alignment: .top)], alignment: .leading, spacing: 16, content: {
                            
                            ForEach(vm.results , id: \.self) { result in
                                PartyInfo(result: result).onTapGesture {
                                    NavigationLink(
                                        destination: SelectedPlaylistView(),
                                        label: {
                                            Text("")
                                        })
                                    
                                }//.padding(.horizontal)
                                //.background(Color.black)
                            }
                            
                
                        }).padding(.horizontal, 20)
                        
                
        }

Solution

  • It doesn't work because it is inside the .onTapGesture it is going into the Void of the closure.

    Replace

     Text("")
    

    With this

     PartyInfo(result: result)
    

    Remove the onTapGesture{} the NavigationLink has it built in.

    It will give you the result you seem to trying to achieve.