Firebase and UISearchbarController searching via the server and not the client -Swift iOS
<p>Does anyone have any info on how to incorporate Firebase into a UISearchController delegate? I can't find any solid info on it. There may possibly be thousands of employees.</p>

<p>I know how to use the search controller delegates <code>updateSearchResultsForSearchController</code> and using a <code>NSPredicate</code> to filter what I'm looking for if I was using NSUserDefaults but using Firebase I'm uncertain.</p>

<p>I've added some more code to my question</p>

<p>I have a custom data model object saved in FirebaseDatabase and I'd like to search on all of the following properties within the object.</p>

<pre><code>lastName
idNumber
deptNumber
position
</code></pre>

<p>Searching any of these properties should first show a partial string inside the table cells until the entire string i'm looking for is shown. So if I typed in the letter "S" then all employee last names beginning with "S" should show. If I enter "Sa" the in would filter to those letters". From my understanding I should use "\u{f8ff}" to get the partial search string but no data is returned.</p>

<p>Anyhow here's all the code</p>

<p>My object is:</p>

<pre><code>class Employee{
var firstName: String?
var lastName: String?
var idNumber: String?
var deptNumber: String?
var position: String?
}
</code></pre>

<p>My paths</p>

<pre><code>-root
  -users
    -uid
      |_"email":"emailAddress"
      |_"userID":"uid"
      |_"firstName":"firstName"
      |_"lastName":"lastName"
  -employees
    -hireDate
      -uid //this is the same uid from the users node so I know who's who
        |_"firstName":"firstName"
        |_"lastName":"lastName"
        |_"idNum":"idNumber"
        |_"deptNumber":"deptNumber"
        |_"position":"position"
</code></pre>

<p>My rules:</p>

<p>What's happening here is the day an employee is hired they are asked to create a company account using their email address and pw.
At the same time a "employees" path is created with a child being a "hireDate" path and finally the employees "uid" path. This employee "uid" is the path I want to search on from the "employees" node</p>

<pre><code>{
  "rules": {
      "users" : {
          "$uid" : {
              ".read": true,
              ".write": "auth != null &amp;&amp; auth.uid == $uid"
          }
      },
      "employees": {
          "$hireDate": {
              "$uid": {
                 ".read": true,
                 ".indexOn": ["lastName", "idNumber", "deptNumber", "position"]
              }
          }
     }
  }
}
</code></pre>

<p>My searchController</p>

<pre><code>import UIKit

class SearchController: UIViewController{

@IBOutlet var tableView: UITableView!

var searchController: UISearchController!
var employeesToFilter = [Employee]()
var filteredSearchResults = [Employee]()


override func viewDidLoad() {
    super.viewDidLoad()
    self.searchController = UISearchController(searchResultsController: nil)

    self.tableView.delegate = self
    //all searchController properties get set here no need to include them though

    let ref = FIRDatabase.database().reference()
    let employeeRef = ref.child("employees")

    employeeRef?.queryOrderedByChild("lastName").queryStartingAtValue("\u{f8ff}").queryLimitedToFirst(20).observeEventType(.ChildAdded, withBlock: {

        (snapshot) in

        if let dict = snapshot.value as? [String:AnyObject]{

            let firstName = dict["firstName"] as! String
            let lastName = dict["lastName"] as! String
            let idNumber = dict["idNumber"] as! String
            let deptNumber = dict["deptNumber"] as! String
            let position = dict["position"] as! String

            let employee = Employee()
            employee.firstName = firstName
            employee.lastName = lastName
            employee.idNumber = idNumber
            employee.deptNumber = deptNumber
            employee.position = position

            self.employeesToFilter.append(employee)
        }
    })
    self.tableView.reloadData()
}

override func viewDidAppear(animated: Bool) {
    self.searchController.active = true
}

deinit {
    self.searchController = nil
}

}


//MARK:- TableView Datasource
extension SearchBuildingController: UITableViewDataSource, UITableViewDelegate{

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
    return self.filteredSearchResults.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
    let cell = self.tableView.dequeueReusableCellWithIdentifier("SearchCell", forIndexPath: indexPath) as! SearchCell

    let searchString = self.filteredSearchResults[indexPath.row]

    cell.firstNameLabel.text = searchString.firstName
    cell.lastNameLabel.text = searchString.lastName
    cell.idNumberLabel.text = searchString.idNumber
    cell.deptNumberLabel.text = searchString.deptNumber
    cell.positionLabel.text = searchString.position
    return cell
}
}

//MARK:- SearchController Delegates
extension SearchController: UISearchResultsUpdating, UISearchBarDelegate, UISearchControllerDelegate{

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    tableView.reloadData()
}

func updateSearchResultsForSearchController(searchController: UISearchController) {

    self.employeesToFilter.removeAll(keepCapacity: false)
    self.filteredSearchResults.removeAll(keepCapacity: false)

    let searchText = self.searchController.searchBar.text

    let searchPredicate = NSPredicate(format: SELF.lastName CONTAINS [c] %@ OR SELF.idNumber CONTAINS [c] %@ OR SELF.deptNumber CONTAINS[c] %@ OR SELF.position CONTAINS [c] %@", searchText!, searchText!, searchText!, searchText!)

    let array = (self.employeesToFilter as NSArray).filteredArrayUsingPredicate(searchPredicate)
    self.filteredSearchResults = array as! [Employee]

    tableView.reloadData()
}
}
</code></pre>