Using the SwiftUI Xcode preview pane, I can click on the rendered views and see the code responsible for that view highlighted in the code pane (and vice versa). However, when I embed the view in a NavigationView
or sometimes even addding a .navigationBarTitle()
to the root view, I can't do that anymore. All views in the Navigation group just becomes one big view and the previewer can't identify the separate underlying pieces anymore.
Is this a bug? Is there a way to get around it? It's a really useful feature and most of my views sit in some kind of Navigation object.
Working
import SwiftUI
struct NavSample: View {
var body: some View {
Text("Hello, World!")
}
}
struct NavSample_Previews: PreviewProvider {
static var previews: some View {
NavSample()
}
}
Not Working
import SwiftUI
struct NavSample: View {
var body: some View {
NavigationView { // Adding this
Text("Hello, World!")
}
}
}
struct NavSample_Previews: PreviewProvider {
static var previews: some View {
NavSample()
}
}