0
votes
  1. I have used fetchedResultsController(FRC) to fetch and list a tableview using fetchedObjects. And the items are listed fine.
  2. I am also having a search bar. On typing any string will update the FRC as shown below & perfomFetch() and reload the tableView.

fetchedResultsController.fetchRequest.predicate = NSPredicate(format: "title CONTAINS[c] %@, text)

Everything is working fine, except when I search faster on searchBar. The crash is happening in cellForRowAtIndexPath & numberOfSections saying that the fetchedObjects is 'Empty'

How to resolve the crash due to fast search ?

1
put the code here - jignesh Vadadoriya
Can You give me a full code - Vignesh J

1 Answers

1
votes

If you have used FetchedResultsController's fetchedObjects count property specify the number of rows in section, sometimes your FetchedResultsController's fetchedObject might be nil in such cases app crashes.

try

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.fetchedResultsController.fetchedObjects?.count ?? 0
    }