[SwiftUI] Where should we add navigationBarTitle?

[SwiftUI] Where should we add navigationBarTitle?

Updated
Sep 19, 2019 2:00 PM
Created
Sep 17, 2019 1:26 PM
Tags
SwiftUI.framework
Keywords

In SwiftUI

When using NavigationView, I'm confused where should I add navigationBarTitle to display title?

🤘

navigationBarTitle should be called on root component of NavigationView. Do not call on NavigationView.

Correct way

var body: some View {
  NavigationView {
    Form {
      Section {
        Text("User 1")
      }
    }
    .navigationBarTitle("Start")
  }
}

image

Does not work

var body: some View {
  NavigationView {
    Form {
      Section {
        Text("User 1")
      }
    }    
  }
	.navigationBarTitle("Start")
}

OR

var body: some View {
  NavigationView {
    Form {
      Section {
        Text("User 1")
      }
      .navigationBarTitle("Start")
    }      
  }
}
image

Other Notes

Notes