SwiftUI: how to use NavigationView in macOS?

I have two separate Xcode projects that I'm using to learn SwiftUI:

  1. A true macOS project (not Catalyst) on Mac.
  2. An iOS project (iPhone).

The following code creates a simple

NavigationView
with master-detail views:


import SwiftUI

struct ListView : View {
    var body: some View {
        NavigationView {
            List() {
                NavigationButton(destination: Text("detail 1")) {
                    Text("row 1")
                }
                NavigationButton(destination: Text("detail 2")) {
                    Text("row 2")
                }
            }
        }
    }
}

#if DEBUG
struct ListView_Previews : PreviewProvider {
    static var previews: some View {
        ListView()
    }
}
#endif


It works as expected on iOS 👍

But on the macOS project the same code as above doesn't work the same way


When I launch the app on Mac, I get this window


And when I click on any row, the detail view just collapses/disappears, never showing me detail view.


Any ideas how to fix this? Maybe I'm missing something? Or perhaps this is just a bug?

Replies

In Beta 2 there's now an error saying than NavigationView is not available on macOS. Let's hope they will stick to their original WWDC session and will implement it later.