     }
     
     private func deleteAllObjects() {
-        if objects.isNonEmpty {
+        if data().isNonEmpty {
             do {
                 try realm.write {
-                    realm.delete(objects)
-                    objects = []
-                    filteredObjects = []
-                    realmView.tableView.reloadData()
+                    realm.delete(data())
+                    resetData()
+                    selectAll.toggle()
                 }
             } catch {
                 print("Couldn't delete all realm objects.")
             }
         }
+    }
+    
+    private func resetData() {
+        objects = []
+        filteredObjects = []
+        selectedObjects = []
     }
     
     private func deleteObjects() {

    func willPresentSearchController(_ searchController: UISearchController) {
        searchController.searchBar.textField?.textColor = .white
    }
}

            do {
                try realm.write {
                    realm.delete(selectedObjects)
                    resetData()
                }
            } catch {
                print("Could not perform deletion. Error \(error)")
