title: Add Search Bar to Existing Header Swift 3
body: <p>I have been adding search boxes and search tab bars to my Swift 3 project based on the Ray Wenderlich tutorial (<a href="https://www.raywenderlich.com/113772/uisearchcontroller-tutorial" rel="nofollow noreferrer">https://www.raywenderlich.com/113772/uisearchcontroller-tutorial</a>)</p>
  
  <p>This has worked well for most tables. However, one of my tables has a header that has been defined in the storyboard. If I use the code as shown below, it replaces the header that is defined in the storyboard, and also has some other side-effects.</p>
  
  <p>I therefore want to know how to do one of the following:</p>
  
  <p>a)append the search bar to the existing header using code
  b)add a searchbar object in the storyboard and then set-up the outlet correctly so that my other search code references it.</p>
  
  <p>I have the following code</p>
  
  <p>In didload</p>
  
  <pre><code>searchController.searchResultsUpdater = self
  searchController.dimsBackgroundDuringPresentation = false
  definesPresentationContext = true
  searchController.searchBar.scopeButtonTitles = ["All", "Active", "Not Active"]
  searchController.searchBar.delegate = self
  tableView.tableHeaderView = searchController.searchBar
  </code></pre>
  
  <p>Extension above main class</p>
  
  <pre><code>extension ItemsViewController: UISearchResultsUpdating{
      func updateSearchResults(for: UISearchController) {
          filterContentForSearchText(searchText: searchController.searchBar.text!)
      }
  }
  
  extension ItemsViewController: UISearchBarDelegate {
      func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
          //filterContentForSearchText(searchText: searchController.searchBar.text!)
          filterContentForSearchText(searchText: searchBar.text!, scope: searchBar.scopeButtonTitles![selectedScope])
      }
  }
  </code></pre>
  
  <p>Filter Code</p>
  
  <pre><code>    func filterContentForSearchText(searchText: String, scope: String = 
  ... filter logic ..     
  tableView.reloadData()
      }
  </code></pre>
  
  <p>any thoughts would be much appreciated</p>