title: Adding a search bar to NavigationView in SwiftUI
body: <p>I'm creating a project using SwiftUI and would like to add a search bar to the navigation bar like what exists in the native settings app, mail app, etc.</p>
  
  <p>I've tried a few things, but can't quite get it to work. The following code runs fine, but the search bar won't show up (I've tried scrolling up) even if I include <code>navigationController.navigationItem.hidesSearchBarWhenScrolling = false</code>. Any help would be appreciated.</p>
  
  <pre><code>//
  //  ContentView.swift
  //  SwiftUITest
  //
  //  Created by me on 1/7/20.
  //  Copyright © 2020 me. All rights reserved.
  //
  
  import SwiftUI
  
  struct HomeView: View {
      var body: some View {
          ScrollView {
              HStack {
                  Spacer(minLength: 0)
  
                  Text("Hello World")
  
                  Spacer(minLength: 0)
              }
          }
          .navigationBarTitle(Text("Search"))
      }
  }
  
  struct SecondView: View {
      var body: some View {
          return Text("Second View")
      }
  }
  
  struct CustomUIViewControllerRepresentation: UIViewControllerRepresentable {
      typealias UIViewControllerType = UINavigationController
  
      func makeUIViewController(context: Context) -&gt; UINavigationController {
          let viewController = UIHostingController(rootView: HomeView())
  
          let navigationController = UINavigationController(rootViewController: viewController)
          navigationController.navigationBar.prefersLargeTitles = true
  
          let searchController = UISearchController()
          navigationController.navigationItem.searchController = searchController
  
          return navigationController
      }
  
      func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {
  
      }
  }
  
  
  struct ContentView: View {
      var body: some View {
          CustomUIViewControllerRepresentation()
      }
  }
  </code></pre>