 extension ContactsViewController: UITableViewDataSource, UITableViewDelegate {
 
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return searchController.active ? Int(filteredFriends.count) : Int(friends.count)
+        return (searchController?.active ?? false) ? Int(filteredFriends.count) : Int(friends.count)
     }
 
     private func friendAtIndexPath(indexPath: NSIndexPath) -> User? {
         let index = indexPath.row
-        let friend = searchController.active ? filteredFriends[safe: index] : friends[safe: index]
+        let friend = (searchController?.active ?? false) ? filteredFriends[safe: index] : friends[safe: index]
         return friend
     }
 


        NSNotificationCenter.defaultCenter().addObserver(self, selector: "syncFriendships", name: FriendsInContactsViewController.Notification.NewFriends, object: nil)


        searchController = UISearchController(searchResultsController: nil)

        searchController.searchResultsUpdater = self
        searchController.dimsBackgroundDuringPresentation = false

        searchController.searchBar.delegate = self
        searchController.searchBar.sizeToFit()

        contactsTableView.tableHeaderView = searchController.searchBar

        contactsTableView.separatorColor = UIColor.yepCellSeparatorColor()
        contactsTableView.separatorInset = YepConfig.ContactsCell.separatorInset


import UIKit
import RealmSwift
import Ruler

class ContactsViewController: BaseViewController {

    @IBOutlet weak var contactsTableView: UITableView!

    var searchController: UISearchController?

    let cellIdentifier = "ContactsCell"

