title: How to filter large array in iOS swift 2 for uisearchbar
body: <p>I am having a <code>UISearchBar</code> with more than 80000 elements in an array and I have to filter this array according to the user input.</p>
  
  <p>But while typing in search view its working very slow means its taking too much time for typing values in keyboard. </p>
  
  <pre><code>func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
  
      if searchText.characters.count == 0 {
          searchActive = false
      } else {
          searchActive = true;
          filtered.removeAllObjects()
  
          dispatch_to_background_queue {
              for sumber in self.data {
                  let nameRange: NSRange = sumber.rangeOfString(searchText, options: [NSStringCompareOptions.AnchoredSearch,NSStringCompareOptions.CaseInsensitiveSearch])
                  if nameRange.location != NSNotFound {
                      self.filtered.addObject(sumber)
                  }
              }//end of for
  
              self.dispatch_to_main_queue {
                  /* some code to be executed on the main queue */
                  self.tableView.reloadData()
              }
          } //end of dispatch
      }
  }
  
  func dispatch_to_main_queue(block: dispatch_block_t?) {
      dispatch_async(dispatch_get_main_queue(), block!)
  }
  
  func dispatch_to_background_queue(block: dispatch_block_t?) {
      let q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
      dispatch_async(q, block!)
  }
  </code></pre>