title: Web service calls doesnt cancel when text changes in UITextField
body: <p>I am searching a text from the service when I type in <code>UITextField</code>. I am using <code>Alamofire</code> library to do service calls. And this is how I call my web service calling function.</p>
  
  <pre><code>func search(){
  
      self.strSkipCount="0"
      com.showProgress()
      self.searchDirectory() { (status) in
  
          print("-----SEARCHING-----")
          self.com.removeProgress()
          if(status){
              self.facesCarousel.reloadData()
              self.setNumberofFaces(count: self.arrayDirectory.count)
          } else {
              self.com.showProgress()
              self.getStaffData() { (status) in
                  self.com.removeProgress()
                  if(status){
                      self.facesCarousel.reloadData()
                      self.setNumberofFaces(count: self.arrayDirectory.count)
                      self.resetMembercountLabel()
                  } else {
                      self.setNumberofFaces(count: self.arrayDirectory.count)
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>In my <code>ViewDidLoad()</code>I have set the target to my text field in this way.</p>
  
  <pre><code>txtSearch.addTarget(self, action: #selector(self.searchTextFieldEditingChanged), for: .editingChanged)
  </code></pre>
  
  <p>Then </p>
  
  <pre><code>func searchTextFieldEditingChanged() {
      if(txtSearch.text != ""){
          self.searchText=txtSearch.text
          //self.cancelPreviousRequest()
         NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(search), object: nil)
          self.search()
      } else {
          self.searchText=""
           NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(searchDirectory(callback:)), object: nil)
          isSearching=false
          prevIndex=0
          self.arrayDirectory=self.arrayPreviouslyLoadedArray
          facesCarousel.reloadData()
          self.resetMembercountLabel()
          self.com.removeProgress()
      }
  }
  </code></pre>
  
  <p>My problem is, Lets say I want to search the name "Alex",Even after found the alex my previous service calls seems not stopping. And it reload with a wrong result. but sometimes it works. Also when delete all the text in the text field and if the text is "" in the textfield. I want to reload with initially loaded dataset. But service calls doesn't stop immidiately after set to "". Please help me.</p>