title: Find a String in a huge text file
body: <p>I am developing an internal App that will search things in one text file (~60,000 lines).
  The user will type a String in the UISearchBar on his iPhone and the App will return the line(s) where the String is located.</p>
  
  <p>This is how I do it.</p>
  
  <p>First I split my text file into an array called <strong>entriesInLine</strong>:</p>
  
  <pre><code>    var entriesInLine: [String] = []
  
      let fileWithEntries = NSBundle.mainBundle().pathForResource("database", ofType: "txt")
      var entriesFromFile = String(contentsOfFile: fileWithEntries!, encoding: NSUTF8StringEncoding, error: nil)
  
      if let content = entriesFromFile {
          self.entriesInLine = content.componentsSeparatedByString("\n")
          println(self.entriesInLine.count)
      }
  </code></pre>
  
  <p>Then I want the user to be able to search the database using the UISearchBar. Here is my Search method:</p>
  
  <pre><code> func filterEntries(searchText: String) {
      for var i = 0; i &lt; self.entriesInLine.count; i++  {
          if ( self.entriesInLine[i].rangeOfString(searchText) != nil) {
              self.filteredEntries.append(extractEntry(entriesInLine[i]))                            
  
          }
  </code></pre>
  
  <p>And here is my <strong>searchDisplayController</strong> method:</p>
  
  <pre><code>func searchDisplayController(controller: UISearchDisplayController!, shouldReloadTableForSearchString searchString: String!) -&gt; Bool {
      self.filterEntries(searchString)
  </code></pre>
  
  <p>}</p>
  
  <p>Everything is kind of working but it's too slow because arrays are huge.</p>
  
  <p>Do you know a faster way of searching the content in my text file?</p>
  
  <p>I will really appreciate your help for that!</p>
  
  <p>Thank you</p>