UISearchController updateSearchResults issue

后端 未结 1 1575
萌比男神i
萌比男神i 2021-01-26 22:25

My question is I have implemented UISearchController in Swift 3 when I tried to filter it\'s easily filtered simple array but my case is little bit different I have

1条回答
  •  旧时难觅i
    2021-01-26 23:06

    Can we just use Swift's built in filter method?

    func updateSearchResults(for searchController: UISearchController) {
      self.tableView.reloadData()
    
      self.filteredRecipeArray.removeAll(keepingCapacity: false)
      guard let searchText = searchController.searchBar.text else {
          return
      }
    
      let array = managerArray.filter {
          return $0.id.range(of: searchText) != nil ||
                 $0.title .range(of: searchText) != nil ||
                 $0.ManagerDesignation.range(of: searchText) != nil
      }
    
      self.filteredRecipeArray = array
    
      self.tableView.reloadData()
    }
    

    EDIT

    Updated the answer to latest Swift 3 syntax

    0 讨论(0)
提交回复
热议问题