   var searchController: UISearchController!
   var suggestedSearchFoods: [String] = []
   var filteredSuggestedSearchFoods: [String] = []
+  var searchString: String?
   
   override func viewDidLoad() {
     super.viewDidLoad()

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
    var foodName: String
    if self.searchController.active {
      foodName = filteredSuggestedSearchFoods[indexPath.row]
    } else {
      foodName = suggestedSearchFoods[indexPath.row]
    }
    cell.textLabel?.text = foodName
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
    return cell
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if self.searchController.active {
      return self.filteredSuggestedSearchFoods.count
    } else {
      return self.suggestedSearchFoods.count


// MARK: UISearchResultsUpdating
extension ViewController: UISearchResultsUpdating {
  func filterContentForSearch (searchText: String, scope: Int) {
    self.filteredSuggestedSearchFoods = self.suggestedSearchFoods.filter({ (food: String) -> Bool in
      var foodMatch = food.rangeOfString(searchText)
      return foodMatch != nil
    })
  }
  
  func updateSearchResultsForSearchController(searchController: UISearchController) {
    self.searchString = self.searchController.searchBar.text
    let selectedScopeButtonIndex = self.searchController.searchBar.selectedScopeButtonIndex
    self.filterContentForSearch(self.searchString!, scope: selectedScopeButtonIndex)
    self.tableView.reloadData()
  }
}

