Why is the Button not working? SwiftUI

I want to create a button, but for some reason it does not work. The text message is not printed in the console.

import SwiftUI

struct Test: View {

    var body: some View {

        NavigationView {

            Text("My Test")

                .navigationTitle("Welcome")

                .toolbar {

                    Button("Help") {

                        print("Help tapped!")

                    }
                }
        }
    }
}

struct Test_Previews: PreviewProvider {

    static var previews: some View {

        Test()
    }
}
Accepted Answer

Works for me...
...make sure you have the Console visible, and not just the Variables View (which uses the same space, and can sometimes hide the Console)

try the following, It gets rid of the layout constraint issues and shows the My Text Label, using an EmptyView as the destination and the help button in the navbar. There is a certain view hierarchy that must be kept to avoid layout issues.

struct ContentView: View {
    @State var selection: String?
    let id = "1"
    var body: some View {
        test
    }

    var test: some View {
        NavigationView {
            NavigationLink(tag: id, selection: $selection) {
                EmptyView()
                    .navigationTitle("Welcome")
            } label: {
                Text("My Test")
            }
            .toolbar {
                Button("Help") {
                    print("Help tapped!")
                }
            }
        }
    }

Example two without the NavigationLink

struct ContentView: View {
    var body: some View {
        nonavLink
    }

    var nonavLink: some View {
        NavigationView {
            Text("My Test")
            .toolbar {
                Button("Help") {
                    print("Help tapped!")
                }
            }
        }
        .navigationTitle("Welcome")
    }
}

Are you trying this in the simulator or in the live preview? print doesn't work in the preview.

Thank you so much guys! I appreciate your help!

Why is the Button not working? SwiftUI
 
 
Q