Search code examples
iphonecocoa-touchxcodecore-dataipod-touch

iOS Filter NSFetchedResultsController Efficiently


I'm attempting to add search support to a Core Data backed UITableView and started to hit some performance issues. I currently have associations to two NSFetchedResultsController (one for regular and one for searching). In my UISearchDisplayDelegate methods I release and recreate my NSFetchedResultsController after each call. However, this causes lag while typing! Is there a more efficient way to filter an NSFetchedResultsController? I've setup my batch size to around 50 items and my database has a few thousand records if that makes a difference. Thanks!


Solution

  • The NSFetchedResultsController documentation makes it pretty clear:

    • If there is a cache, delete it.
    • Update the fetchRequest property. Note that you cannot simply modify the existing fetch request; you must create a new one.
    • Call -executeFetch:.