I tried to debug and trace what line the error occur , and I found out the error occur after reading the print(tcb_filteredArray)
and I tried to put the print(tcb_filteredArray)
below the self.tableView.reloadData()
and make a debug and trace it again and it still error occur in print(tcb_filteredArray)
My search filtering code
let realm = try! Realm()
let tcb = realm.objects(TrialCourtBranches.self)
let tcb_safe = ThreadSafeReference(to: tcb)
DispatchQueue.global(qos: .userInitiated).sync {
guard let filtered = realm.resolve(tcb_safe) else{ return }
tcb_filteredArray = filtered.filter({ $0.branch_name.lowercased().contains(searchText.lowercased()) || ($0.loc?.pc?.province.lowercased().contains(searchText.lowercased()))! || ($0.loc?.pc?.city_municipality.lowercased().contains(searchText.lowercased()))! || $0.office_no.lowercased().contains(searchText.lowercased())})
DispatchQueue.main.async {
self.tableView.reloadData()
}
}