title: Live search throttle in Swift 3
body: <p>I'm trying to live search at my PHP API with Swift. Until now i've done this thing.</p>
  
  <pre><code> var filteredData = [Products]()
  
  
   func getSearch(completed: @escaping DownloadComplete, searchString: String) {
  
          let parameters: Parameters = [
              "action" : "search",
              "subaction" : "get",
              "product_name"  : searchString,
              "limit" : "0,30"
          ]
          Alamofire.request(baseurl, method: .get, parameters: parameters).responseJSON { (responseData) -&gt; Void in
              if((responseData.result.value) != nil) {
                  let result = responseData.result
  
                  if let dict = result.value as? Dictionary&lt;String, AnyObject&gt;{
                      if let list = dict["products_in_category"] as? [Dictionary&lt;String, AnyObject&gt;] {
                          if self.filteredData.isEmpty == false {
                              self.filteredData.removeAll()
                          }
                          for obj in list {
                              let manPerfumes = Products(productDict: obj)
                              self.filteredData.append(manPerfumes)
                          }
                      }
                  }
                  completed()
              }
          }
      }
  
  
  extension SearchViewController: UISearchResultsUpdating {
  
      func updateSearchResults(for searchController: UISearchController) {
  
          if (searchController.searchBar.text?.characters.count)! &gt;= 3 {
                      self.getSearch(completed: {
                      self.searchResultTable.reloadData()
  
                      self.searchResultTable.setContentOffset(CGPoint.zero, animated: true)
                  }, searchString: searchController.searchBar.text!)
  
  
          } else {
              self.searchResultTable.reloadData()
          }
  
  
      }
  }
  </code></pre>
  
  <p>And the table view is being updated with the <code>filteredData</code>.
  How can i throttle the search so lets say when the user writes</p>
  
  <pre><code>"example" -&gt; shows the results with example
  then he erase the "le" -&gt; 
  "examp" -&gt; if the previous request is not completed, cancel it -&gt; make request for "examp" and show the data in table view!
  </code></pre>
  
  <p>P.S. from another answer i found</p>
  
  <pre><code>func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
      // to limit network activity, reload half a second after last key press.
      NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(self.reload), object: nil)
      self.perform(#selector(self.reload), with: nil, afterDelay: 0.5)
  }
  func reload() {
      print("Doing things")
  }
  </code></pre>
  
  <p>Although if I try to replace "self.reload" with my function, I get an error 
  <code>cannot convert value of type () to expected argument type selector</code></p>