title: SwiftUI - Add a Navigation Bar Button on Condition
body: <p>Given i have a view like this..</p>
  <pre><code>@State var tabIndex: Int = 0
             
   var body: some View {
  
    TabView(selection: $tabIndex)
    {
     Text(&quot;Tab 1&quot;).tabItem({
      Image(systemName: &quot;message&quot;)
     }).tag(0)           
                  
     Text(&quot;Tab 2&quot;).tabItem({
      Image(systemName: &quot;arkit&quot;)
     }).tag(1)             
            
     Text(&quot;Tab 3&quot;).tabItem({
      Image(systemName: &quot;battery.100&quot;)
     }).tag(2)
    }.navigationBarTitle(&quot;Tabbed View&quot;)
              
   }
  </code></pre>
  <p>This produces a view like this which is what is expected:</p>
  <p><a href="https://i.stack.imgur.com/AUTRB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AUTRB.png" alt="enter image description here" /></a></p>
  <p>to add a navigation button to the bar i can use</p>
  <pre><code> .navigationBarItems(trailing:
    Button(action: {print(&quot;Button was tapped&quot;)}) {
     Image(systemName: &quot;plus&quot;)
      .resizable().frame(width: 20, height: 20)
    })
  </code></pre>
  <p>Which adds the button as <a href="https://i.stack.imgur.com/NFQlQ.png" rel="noreferrer">expected</a></p>
  <p>Is there any way to only add (or show) the button based on a condition?</p>
  <pre><code>if (self.tabIndex == 1){
    show button
  }
  else {
   don't show button
  }
  </code></pre>