title: SwiftUI Search bar unable to product diagnostic error
body: <p>I am trying to implement a search bar using this tutorial: <a href="https://www.appcoda.com/swiftui-search-bar" rel="nofollow noreferrer">https://www.appcoda.com/swiftui-search-bar</a> .</p>
  <p>I can get the search bar to display and to take text but it does nothing with that text because it's not used at this stage to filter.</p>
  <p>When I try to use it to filter my list of products - taken from Firestore - it throws a <code>Failed to produce diagnostic for expression; please submit a bug report</code> error.</p>
  <pre><code>struct ProductList: View {
      @State private var searchText: String = &quot;&quot;
      
      // ProductsModel() is the Class that this structure is looking at. If anything in ProductsModel changes, then - because it is an ObservableObject - then this structure/view ProductList will update with the new information.
      @ObservedObject private var viewModel = ProductsModel()
      
      var body: some View {
          NavigationView{
              VStack{
                  
                  HStack{
                  NavigationLink(destination: ProductCreationView()){Text(&quot;Add Product&quot;)}
                  NavigationLink(destination: Initialinfo()){Text(&quot;Help&quot;)}
                  } //Navigation Links
                  
                  SearchBar(text: $searchText)
                  
                  List(viewModel.product_fire.filter({ searchText.isEmpty ? true : $0.product_name.contains(searchText) })){ product in
                      NavigationLink(destination: ProductDetail(product: product))
                      {ItemRow(product: product).navigationBarTitle(&quot;Products&quot;, displayMode: .inline)}
                      }.onAppear(){
                          self.viewModel.fetchData()
                      }
                  
                  
                  // Create a list of all products where each product is given a link that points to the specific product detail page as well as the description taken from the ItemRow view for that product.
                  // This displays as : Product Name/Link
                  //                      Product Brand
                  //                    ...
                  List(viewModel.product_fire, id:\.product_name) { product in
                  NavigationLink(destination: ProductDetail(product: product))
                  {ItemRow(product: product).navigationBarTitle(&quot;Products&quot;, displayMode: .inline)}
                  }.onAppear(){
                      self.viewModel.fetchData()
                  }
  </code></pre>
  <p>If I comment out the code for the filtered version it displays fine and pulls all products from the database and displays with Name/Link and Brand as a pair for each product as one large list.</p>
  <p>From reading other problems RE this error - but none about search bars - it seems to be a problem with { } placement etc but no amount of tinkering has helped.</p>
  <p>Edit 1:
  I created a function that takes in the searchText and then searches the Firestore for documents that have the documentID equal to the searchText (these should be unique).</p>
  <pre><code>func singleData(searchText: String){
      db.collection(&quot;Products&quot;).whereField(&quot;code&quot;, isEqualTo: searchText)
          .getDocuments() { (querySnapshot, err) in
              if let err = err {
                  print(&quot;Error getting documents: \(err)&quot;)
              } else {
                  for document in querySnapshot!.documents {
                      print(&quot;\(document.documentID) =&gt; \(document.data())&quot;)
                  }
              }
      }
  }
  </code></pre>
  <p>The List and NavigationLinks in the <code>ProductList</code> view have been swapped out for:</p>
  <pre><code>        Text(&quot;Test&quot;).onAppear(){
              self.viewModel.singleData(searchText: String)
          }
  </code></pre>
  <p>with the intention that if the searchText is an existing document then it will pass that code on to the <code>ProductDetail</code> view and take the user straight there, and remove the need for the Lists.
  It prints the product data to the console but I am running into problems trying to return the value back to the view as it gives a void type error.</p>
  <p>Many thanks.</p>