     
     /// Returns a class object at a specified index path
     private func classObj(at path: IndexPath) -> Class {
-        return classes[path.section][path.row]
+        if searchController.isActive {
+            return filteredClasses![path.row]
+        } else {
+            return classes[path.section][path.row]
+        }
     }
     
     /// Deletes a class from Realm

        reloadEmptyState()
        
        // Present snack bar to allow undo
        let snack = LPSnackbar(title: "Class deleted.", buttonTitle: "UNDO", displayDuration: 3.0)
        snack.viewToDisplayIn = self.view
        snack.bottomSpacing = (tabBarController?.tabBar.frame.height ?? 0) + 12
        

    }
}

extension ClassesTableViewController: UISearchBarDelegate {
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        guard searchText != "" else {
            self.searchController.isActive = false
            self.tableView.reloadData()
            self.reloadEmptyState()
            return
        }
        
        // Update classes array to filter for name
        self.filterClasses(for: searchText)
        self.tableView.reloadData()
    }
    
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        self.searchController.isActive = false
        self.tableView.reloadData()
        self.reloadEmptyState()
    }
}

// MARK: Segues

extension ClassesTableViewController: Segueable {
