Unresolved identifier 'NavigationButton'

Hi There!

I'm a beginner in Swift - so let me begin with a beginner question. Right now I'm learning how to create views in SwiftUI and I wanted to navigate between them. According to some YouTube-Tutorials something like that should work:

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationButton(destination: Text("Ups.. es geht")) {
                Text("Navi-Test")
            }
        }
    }
}

Actually it doesn't work, I get the error "Use of unresolved identifier 'NavigationButton'" - why?...
In the tutorials I've seen it seems to work.

And - how to navigate from one View to another without clicking a button? Just by code?

Tutorials you're seeing are outdated - it's called NavigationLink now

This works for me. Is it the correct way? No idea. There is approximately zero documentation from Apple

struct ContentView: View {
    @State var foo: Bool = false
    var body: some View {
        VStack {
            NavigationView {
                NavigationLink(destination: Text("Ups.. es geht"), isActive: $foo) {
                    Text("Navi-Test")
                }
            }
            Button(action: { self.foo = true }) {
                Text("button!")
            }
        }
    }
}

SwiftUI is not part of Swift. It is a private Apple framework. You are encouraged to post a question on Apple-specific forums such as the Apple Developer forums, StackOverflow, other web resources. It is discouraged to ask about private Apple systems on this forum which is dedicated to the Swift language itself, regardless of platform.

1 Like