title: UISearchBar crashing after filtering in Swift
body: <p>I'm trying to make my app iOS 7 compatible with a search bar.  So that means I can't use <code>UISearchController</code> (like I would far prefer to be doing).  So I'm trying to implement the search bar with <code>searchDisplayController</code>.  But whenever I run the app and enter text into the search bar, the app crashes.</p>
  
  <p>I plugged in a few break points to see when exactly this is happening, and it seems that it happens at the <code>numberOfRowsInSection</code> function.  Although I have no idea why that is because when I print to the console in this function, right before crash the filtered data array is what I would expect it to be given the input text in the status bar.</p>
  
  <p>So here is my code.  Maybe I'm missing something.  A second set of eyes on this is greatly appreciated.  Thanks!</p>
  
  <pre><code>class RegData2: UITableViewController, UISearchBarDelegate, UISearchDisplayDelegate {
  
      // Beginning to ios7 compatibility    
  
  
      let model = Model()
      var prevArray = [String]()
      var selectionPrev = String()
      var selection : String = ""
      var filteredTableData = [String]()
      var int = 0
  
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
          // Reload the table
          self.tableView.reloadData()
  
      }
  
      override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1
      }
  
  
      override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          if (tableView == self.searchDisplayController?.searchResultsTableView) {
              return self.filteredTableData.count
          }
          else {
  
              return prevArray.count
  
          }
      }
  
  
      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell!
          cell.textLabel?.font = UIFont.boldSystemFontOfSize(18)
  
  
          if (tableView == self.searchDisplayController?.searchResultsTableView) {
              cell.textLabel?.text = filteredTableData[indexPath.row]
              return cell
          }
          else {
  
              cell.textLabel?.text = prevArray[indexPath.row]
              return cell
          }
      }
  
      override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
      {
          tableView.deselectRowAtIndexPath(indexPath, animated: true)
  //        controller.searchBar.resignFirstResponder()
  
          if (tableView == self.searchDisplayController?.searchResultsTableView) {
              selection = filteredTableData[indexPath.row]
          }
          else {
              selection = prevArray[indexPath.row]
          }
  
          performSegueWithIdentifier("regData2ToRegView", sender: self)
  
  
  
      }
  
  
      override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
          if segue.identifier == "regData2ToRegView" {
  
              let regView = segue.destinationViewController as! RegView
              regView.prevSelection = selection
              regView.prevSelectionType = selectionPrev
  
  
          }
  
      }
  
  
      func filterContentForSearchText(searchText: String, scope: String = "Title") {
  
          filteredTableData = prevArray.filter({( item : String) -&gt; Bool in
  
              var match = (scope == "Title")
              var stringMatch = item.rangeOfString(searchText)
  
              return match &amp;&amp; (stringMatch != nil)
          })
      }
  
  
      func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchString searchString: String?) -&gt; Bool {
  
          self.filterContentForSearchText(searchString!, scope: "Title")
  
          return true
  
      }
  
      func searchDisplayController(controller: UISearchDisplayController, shouldReloadTableForSearchScope searchOption: Int) -&gt; Bool {
          self.filterContentForSearchText(self.searchDisplayController!.searchBar.text!, scope: "Title")
  
          return true
  
      }
  
  }
  </code></pre>