How to make sequential filters with NSFetchedResultsController
I want to make sequential filters using NSFetchedResultsController. The goal is to display the more relevant results first.
For example : Entity person: name - country
1) The persons where the name contains by the search string.
2) The persons where the country开发者_如何学Python contains the search string.By sequential, I mean that I want to have first the search results 1) and then 2).
I don't know the right way to do that because you init NSFetchedResultsController with 1 NSFetchRequest. But here, I need 2 NSFetchRequest. The other problem using 2 requests is that I could generate duplicate items with the second request.
Is it possible to deal with that using NSFetchedResultsController ?
Thanks
Here is an example :
record 1 : name : Peter country : Mauritius
record 2 : name : Marc country : Mauritania
record 3 : name : Maureen country : Belgium
If the user types "ma" in the searchbar:
I want to display first the name results and then the country results.
So here, the results would be in this order :
- Marc ("MA"rc)
- Maureen ("MA"ureen)
- Peter ("MA"uritius)
Two different things going on here: filtering and sorting.
you can do sorting by calling setSortDescriptors
on your NSFetchRequest. It take an array of sort descriptors and each one would correspond to name or country or whatever.
filtering is done by predicates. Use setPredicate:
on your NSFetchRequest. You only get one predicate, but it can have multiple criteria using and and or.
精彩评论