Sort NSFetchedResultsController by NULL NSDates

I have a table view that goes through an array of data. Data is a set of contacts that may have a reminder time attached to them. For example:

  • Jessica
  • John
  • Bill
  • Katrina (February 9)
  • Brian (February 11)

Currently, it sorts the table view through the core-data attribute reminderDatein ascending order. It is working correctly. The only catch I would like to use for elements with NULL reminderDatethat should be dumped at the end NSFetchedResultsController, not at the beginning.

Ideally, it would look like this:

  • Katrina (February 9)
  • Brian (February 11)
  • Jessica
  • John
  • Bill

NSSortDescriptor, NSFetchedResultsController. , NSFetchedResultsController, , .

, :

NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"User"];
NSSortDescriptor *sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"reminderDate" ascending:YES];

[fetchRequest setSortDescriptors:@[sortByDate]];
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                                                    managedObjectContext:context
                                                                      sectionNameKeyPath:nil
                                                                               cacheName:nil];

, sortDescriptor, , .

+4
1

, : NSSortDescriptor

BOOL, , . , , .

NSSortDescriptor *sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"reminderDate" ascending:YES];
NSSortDescriptor *sortByHasReminder = [NSSortDescriptor sortDescriptorWithKey:@"hasReminder" ascending:NO];

. , , , NSSFetchedResultsController.

+5

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


All Articles