 extension ContactsViewController: UITableViewDataSource, UITableViewDelegate {
 
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return Int(friends.count)
+        return searchController.active ? Int(filteredFriends.count) : Int(friends.count)
     }
 
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
 
         let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as! ContactsCell
 
-        if let friend = friends[safe: indexPath.row] {
+
+        let index = indexPath.row
+        let friend = searchController.active ? filteredFriends[safe: index] : friends[safe: index]
+
+        if let friend = friend {
 
             let radius = min(CGRectGetWidth(cell.avatarImageView.bounds), CGRectGetHeight(cell.avatarImageView.bounds)) * 0.5
 

        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)

        if let friend = friends[safe: indexPath.row] {
            performSegueWithIdentifier("showProfile", sender: friend)
        }
   }

    let cellIdentifier = "ContactsCell"

    lazy var friends = normalFriends()
    var filteredFriends: Results<User>!

    struct Listener {
        static let Nickname = "ContactsViewController.Nickname"
