title: Q: Search Bar and Search Display Controller in storyboard with swift and Xcode8.0 crash at Appdelegate
body: <p>Storyboard layout is below:</p>
  <p><a href="https://i.stack.imgur.com/06efM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/06efM.png" alt="This is my storyboard layout" /></a></p>
  <p>This is my demo, and I don't know where the error comes out.</p>
  <p>In <code>ViewController</code>:</p>
  <pre><code>import UIKit
  import Foundation
  
  class ViewController: UIViewController {
  
  @IBOutlet weak var tableView: UITableView!
  
  
  @IBOutlet var searchDisplay: UISearchDisplayController!
  
  var ctrls:[String] = [&quot;Label&quot;,&quot;Button1-init&quot;,&quot;Button1-high&quot;,&quot;Button2-init&quot;,&quot;Button2-high&quot;,&quot;Switch&quot;]
  
  var ctrlsel:[String] = []
  
  override func viewDidLoad() {
      super.viewDidLoad()
      
      self.ctrlsel = self.ctrls
      self.searchDisplay.searchResultsTableView.register(UITableViewCell.self,
                                                              forCellReuseIdentifier: &quot;SwiftCell&quot;)
  
      self.searchDisplay.searchBar.placeholder = &quot;input&quot;
  
      //self.searchDisplay.searchBar.text = &quot;b&quot;
  
      self.searchDisplay.searchBar.prompt = &quot;search&quot;
  
      self.searchDisplay.searchBar.searchBarStyle = UISearchBarStyle.minimal
  
      self.searchDisplay.searchBar.showsScopeBar = true
      self.searchDisplay.searchBar.scopeButtonTitles = [&quot;all&quot;,&quot;part&quot;,&quot;high&quot;]
  }
  
  func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -&gt; Int {
      return self.ctrlsel.count
  }
  
  
  func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!)
      -&gt; UITableViewCell!
  {
  
      let identify:String = &quot;SwiftCell&quot;
  
      let cell = self.searchDisplay.searchResultsTableView.dequeueReusableCell(
          withIdentifier: identify, for: indexPath as IndexPath) as UITableViewCell
      cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
      cell.textLabel?.text = self.ctrlsel[indexPath.row]
      return cell
  }
  
  func searchBar(searchBar: UISearchBar!, textDidChange searchText: String!) {
      self.searchText = searchText
      searchCtrls()
  }
  
  func searchBar(searchBar: UISearchBar!, selectedScopeButtonIndexDidChange selectedScope: Int) {
      print(selectedScope)
      searchCtrls();
  }
  
  var searchText:String = &quot;&quot;
  
  
  func searchCtrls() {
  
      if self.searchText == &quot;&quot; {
          self.ctrlsel = self.ctrls
      }
      else {
          var scope = self.searchDisplay.searchBar.selectedScopeButtonIndex;
  
          self.ctrlsel = []
          for ctrl in self.ctrls {
              let lc = ctrl.lowercased()
              if lc.hasPrefix(self.searchText) {
                  if (scope == 0 || (scope == 1 &amp;&amp; lc.hasSuffix(&quot;init&quot;))
                      || (scope == 2 &amp;&amp; lc.hasSuffix(&quot;high&quot;))) {
                      self.ctrlsel.append(ctrl)
                  }
              }
          }
      }
      
  
      // self.searchDisplay.searchResultsTableView.reloadData()
  }
  
  }
  </code></pre>
  <p>Crash at Appdelegate. In the <code>swift3</code> and <code>Xcode 8.0</code> environment. To convenient get search result ,use <code>Search Bar and Search Display Controller in storyboard</code>.</p>
  <p>When I run my application, it crash at :<code>class AppDelegate: UIResponder, UIApplicationDelegate </code> this line in<code> Appdelegate.swift</code>.The break info is : <code>Thread 1: breakpoint 2.1</code></p>
  <p><strong>EDIT:</strong></p>
  <p>after set <code>dataSource</code> and <code>delegate</code> of tableView to <code>vc</code>: there comes a strange scenario：the <code>searchbar</code> is under the <code>tableView</code></p>