title: SwiftUI: How to set the title for the toolbar on macOS 11?
body: <p>I have a SwiftUI app that has two columns and a toolbar. I'm trying to emulate the latest macOS applications and use the toolbar in the same way that Mail does, i.e. select a sidebar item and show that as the title of the window.</p>
  <p>Here is my code:</p>
  <pre><code>import SwiftUI
  
  var listItems = [&quot;Item 1&quot;, &quot;Item 2&quot;, &quot;Item 3&quot;, &quot;Item 4&quot;]
  var secondItems = [&quot;Second 1&quot;, &quot;Second 2&quot;, &quot;Second 3&quot;, &quot;Second 4&quot;]
  
  struct ContentView: View
  {
      
      @State var select: String? = &quot;Item 1&quot;
      var body: some View
      {
          VStack
          {
              NavigationView
              {
                  List
                  {
                      ForEach((0..&lt;listItems.count), id: \.self)
                      {index in
                          NavigationLink(destination: SecondView(), tag: listItems[index], selection: $select)
                          {
                              Text(listItems[index])
                                  .padding(.vertical, 2.0)
                          }
                      }
                      Spacer()
                  }.frame(width:160)
              }
              
              .toolbar
              {
                  Text(&quot;this is not the title&quot;)
                  Button(action: {})
                  {
                      Label(&quot;Upload&quot;, systemImage: &quot;square.and.arrow.up&quot;)
                  }
              }
          }
      }
  }
  
  struct SecondView: View 
  {
      var body: some View 
      {
          NavigationView 
          {
              List
              {
                  ForEach((0..&lt;secondItems.count), id: \.self)
                  {index in
                      NavigationLink(destination: Text(secondItems[index]))
                      {
                          Text(secondItems[index])
                              .frame(height: 20)
                      }
                  }
              }.frame(width:150)
          }
          
      }
  }
  </code></pre>
  <p>So I get a toolbar like this:</p>
  <p><a href="https://i.stack.imgur.com/jnQ1D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jnQ1D.png" alt="enter image description here" /></a></p>
  <p>but how do I set the title of the window in the toolbar when I select an item in the first list?</p>