         switch type {
             case .Insert:
                 if let _newIndexPath = newIndexPath {
-                tableView.insertRowsAtIndexPaths([_newIndexPath], withRowAnimation: .Fade)
+                    tableView.insertRowsAtIndexPaths([_newIndexPath], withRowAnimation: .Fade)
                 }
             case .Delete:
                 if let _indexPath = indexPath {
-                tableView.deleteRowsAtIndexPaths([_indexPath], withRowAnimation: .Fade)
+                    tableView.deleteRowsAtIndexPaths([_indexPath], withRowAnimation: .Fade)
                 }
             case .Update:
                 if let _indexPath = indexPath {
-                tableView.reloadRowsAtIndexPaths([_indexPath], withRowAnimation: .Fade)
+                    tableView.reloadRowsAtIndexPaths([_indexPath], withRowAnimation: .Fade)
                 }
             default:
                 tableView.reloadData()

    func controllerDidChangeContent(controller: NSFetchedResultsController) {
        tableView.endUpdates()
    }
    
//    override func viewWillAppear(animated: Bool) {
//        super.viewWillAppear(animated)
//        
//        if let notes = Note.getAllNotes() {
//            self.notes = notes
//            self.tableView.reloadData()
//        }
//    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

import UIKit
import CoreData

class NotesTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, NSFetchedResultsControllerDelegate, UISearchResultsUpdating {

    var notes = [Note]()
    
    var searchResults = [Note]()
    
    @IBOutlet weak var tableView: UITableView!
    
    var fetchResultController:NSFetchedResultsController!
    
    var searchController:UISearchController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupFetchResultsController()
        
        setupSearchController()
        
        title = "Beyond"
        tableView.tableFooterView = UIView()
        
        // Remove the title of the back button
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
    }
    
    func filterContentForSearchText(searchText: String) {
        searchResults = notes.filter({ note in
        note.title.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch) != nil
        })
    }
    
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        if let searchText = searchController.searchBar.text {
            filterContentForSearchText(searchText)
            tableView.reloadData()
        }
    }
    
    func setupSearchController() {
        searchController = UISearchController(searchResultsController: nil)
        searchController.searchResultsUpdater = self
        searchController.dimsBackgroundDuringPresentation = false
        definesPresentationContext = true
        tableView.tableHeaderView = searchController.searchBar
        
        searchController.searchBar.placeholder = "Search notes..."
        searchController.searchBar.tintColor = UIColor.whiteColor()
        searchController.searchBar.barTintColor = UIColor(red: 30.0/255.0, green:
        30.0/255.0, blue: 30.0/255.0, alpha: 1.0)
    }
    
    func setupFetchResultsController() {
