Search code examples
swiftcore-datansfetchedresultscontroller

CoreData: Can I perform a method on a FetchRequest results as it searches?


I have a TableView that lists very simple CoreData objects (they contain a name String and a couple of other fields).

I am using a FetchedResultsController, so my TableView currently uses 'fetchedResultsController.object(at: indexPath)' to populate the cells.

In my code, I have a function that converts the CoreData object .name property into a different value (i.e. "dog" might become "cat").

I want to add a search to my TableView, but I want it so the user can also search for the changed values (i.e. they can search for "dog" or they can search for "cat").

Is there a fetchRequest property I can use to perform a FetchResults query/custom filter function simultaneously?


Solution

  • There wasn't a solution to this using predicates (which can't use transient / computed values etc), so I ended up removing the FetchedResultsController, and doing my own filtering after my FetchRequests.