Note that there are some explanatory texts on larger screens.

plurals
  1. POCore Data sort tableview by formatted date
    primarykey
    data
    text
    <p>I know how to sort Core Data objects in a tableview by NsDate, but this by default seems to create a new section for each object. I want to sort them by a medium formatted date with NSDateFormatter. How would I do this?</p> <p>For example, if I have 3 objects created on the same day, I want them to be in the same section with the section title being that Day, no time needed.</p> <p>Each object has an NSDate property. Thanks for your help.</p> <p>This is the code I have in fetchedResultsController with rgeorge's suggestions. What am I missing here?</p> <pre><code>- (NSFetchedResultsController *)fetchedResultsController { if (fetchedResultsController != nil) { NSLog(@"get old fetched controller"); return fetchedResultsController; } else{ NSLog(@"get new fetched controller"); } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"InTextEntity" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; [fetchRequest setFetchBatchSize:20]; NSSortDescriptor *dateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"dateModified" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:dateDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"mediumFormattedDate" cacheName:@"Root"]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; NSError *error = nil; if (![fetchedResultsController performFetch:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } return fetchedResultsController; </code></pre> <p>} </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload