title: How to filter large array using Swift-2 for high performance
body: <p>I tried while typing in search-bar its results should be updates in table view, for that I'm filtering data dynamically while typing. </p>
  
  <p>It works well when I tested in simulator, but actually running on iPhone, while typing it gives very slow response. </p>
  
  <p>I know, due to large array i.e. array of 100000 records, due to this it might be giving me slow response.</p>
  
  <p>This is my actual filtering stuff, in which when user start typing it will filter the data.   </p>
  
  <pre><code>   func searchBar(searchBar: UISearchBar, textDidChange searchText: String)
              {
                    self.filtered = self.data.filter({ (text) -&gt; Bool in
  
                          let tmp: NSString = text
                          let range = tmp.rangeOfString(searchText, options: [NSStringCompareOptions.CaseInsensitiveSearch , NSStringCompareOptions.AnchoredSearch])
                      return range.location != NSNotFound
  
                  })
  
  
                  if(self.filtered.count == 0)
                  {
                      self.searchActive = false;
                  }
                  else
                  {
                      self.searchActive = true;
                      self.tableView.reloadData()
                  }
                  if(searchBar.text == "")
                  {
                      searchBar.resignFirstResponder()
                  }
                  self.tableView.reloadData()
  
                  searchBar.showsCancelButton = true
                  self.ContainerView.hidden=true
                  self.tableView.hidden=false
                  if(searchBar.text != "")
                  {
                      self.ContainerView.hidden=true
                      self.tableView.hidden=false
                  }
          }
  </code></pre>
  
  <p>How do I need to implement it, in such a way that it should filter it fast and provide fast response ?</p>
  
  <p>Whether I should implement it with "multithreading" &amp; how?</p>
  
  <p>Even I tried this stuff using following methods...</p>
  
  <p>dispatch_to_background_queue {} 
                  &amp; 
      func dispatch_to_main_queue(block: dispatch_block_t?) {
        dispatch_async(dispatch_get_main_queue(), block!)
       }</p>
  
  <p>Please suggest me proper solution for this.</p>