title: How to pass the selected object in a List to a second view when a button in a row is tapped
body: <p>In the following code, I have a list that has a button in each row. What I want is to be able to pass the selected <code>Fruit</code> from the <code>ContentView</code> to the <code>SecondView</code> when the button is tapped. Right now I can present the <code>SecondView</code> but it's blank, it has no text in it, in other words, I don't see the text, <code>Second View: [fruit name]</code>. Please note that I cannot use the <code>NavigationLink(destination:)</code> because I'm already using it to go to a details view when the rows are tapped.</p>
  <p>How can I pass the selected fruit to the <code>Second View</code> when the button on each row is tapped?</p>
  <h2>Fruit Object</h2>
  <pre><code>struct Fruit: Identifiable{
      var id = UUID()
      var name:String
  }
  </code></pre>
  <h2>Content View:</h2>
  <pre><code>struct ContentView: View {
      @State private var secondViewIsPresented = false
      
      var fruits = [Fruit(name: &quot;Apple&quot;), Fruit(name: &quot;Orange&quot;)]
      
      var body: some View {
          List{
              ForEach(fruits){ fruit in
                  HStack{
                      Text(fruit.name)
                      
                      Button(&quot;Tap Me&quot;){
                          secondViewIsPresented.toggle()
                          SecondView(selectedFruit: fruit)
                      }
                      .frame(width:150, height: 35)
                      .background(Color.blue)
                      .buttonStyle(BlueButton())
                  }
              }
          }
          .sheet(isPresented: $secondViewIsPresented){
              // Here I cannot access the selected fruit
          }
      }
  }
  
  // style to make the button in the row work properly
  // I'm showing it just for reference.
  struct BlueButton: ButtonStyle {
      func makeBody(configuration: Self.Configuration) -&gt; some View {
          configuration.label
              .scaleEffect(configuration.isPressed ? 2 : 1)
      }
  }
  </code></pre>
  <h2>Second View</h2>
  <pre><code>struct SecondView: View {
      var selectedFruit: Fruit
      
      var body: some View {
          Text(&quot;Second View: \(selectedFruit.name)&quot;)
      }
  }
  </code></pre>