3lvis / DATASource

Core Data's NSFetchedResultsController wrapper for UITableView and UICollectionView
Other
106 stars 27 forks source link

How to change predicate on fetchrequest? #110

Closed petkrein closed 6 years ago

petkrein commented 6 years ago

Hey 3lvis,

i need to change the predicate when text change called on e.g. SearchBar. But there is no way to access the fetchedResultController to update the predicates!

What i need is something like this:

let frc = myDataSource.fetchedResultsController
frc.fetchRequest.predicate = NSPredicate(format: "firstname CONTAINS[cd] %@", searchString)
try! frc.performFetch()

tableView.reloadData()
3lvis commented 6 years ago

Hi Peter! I hope you're having a nice weekend. I've gotten this question before so I'll make sure to update the README if I'm right in understanding what you want.

You can do

dataSource.predicate = myNewPredicate

And everything should work. Let me know if this doesn't solve your issue :)

petkrein commented 6 years ago

Hi 3lvis,

you are right, the predicate feature was added in Version 6.1.7. (my pod Version 6.1.5).

Thank you and that solves my issue.

3lvis commented 6 years ago

You're welcome, have a great week :)