Predicate NSFetchRequest

I have a SQLite-enabled data warehouse and want to get a list of managed objects with NSFetchRequest. I want the specified list to be sorted by a boolean value that can be easily calculated at the database level. I know this because the same conditions can be formulated using NSPredicatewhich would look like this:

[NSPredicate predicateWithFormat:@"uid = %@", currentUID]

Unfortunately, it seems that there is no way to formulate such a condition using NSSortDescriptor. How am I best to do this? Do I get two lists, one with

[NSPredicate predicateWithFormat:@"uid = %@", currentUID]

and one with

[NSPredicate predicateWithFormat:@"uid != %@", currentUID]

and combine them later? Can I still use it elegantly NSFetchedResultsController?
Or should I get all the elements and sort them later in the code? Or I didn’t miss anything.

+3
source share
2 answers

Just create an array (even if it contains only one element) NSSortDescriptorsto sort the result as desired.

You use setSortDescriptors:to install them.

An extract can simultaneously process both predicates and sort.

0
source

What you are asking for does not make sense.

, . , , YES NO ( ). YES, . NO, . .

less than, equal greater than. , ( ). ( ), . API , .

, : ? , -, ?

-1

Source: https://habr.com/ru/post/1792774/


All Articles