Snowman
Snowman

Reputation: 32091

Sorting Core Data fetch results

My NSManagedObject has a property NSDate with format: 2012-03-27 14:43:22 +0000. I want to sort my results by date, so I do: NSSortDescriptor *sort= [[NSSortDescriptor alloc] initWithKey:@"createDate" ascending:NO selector:@selector(compare:)];

And I separate into sections using sectionNameKeyPath: NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:@"createDate" cacheName:nil];

However, I want to sort by days, not by exact date. Currently, if I have two createDates of the same day but seconds apart, they are sorted into separate sections. I want to sort all objects with the same day into the same section. How would I do this?

Upvotes: 1

Views: 455

Answers (2)

Gobot
Gobot

Reputation: 2480

Here's two posts that I came across the other day that discuss non-standard sections. It will give you a few cool directions and ideas:

Using custom sections with NSFetchedResultsController?
Group by weekdays with Core Data

Upvotes: 0

yibuyiqu
yibuyiqu

Reputation: 718

Just a rough thought. You can store the date with string "2012-03-27", I think you can sort them by days.

Upvotes: 1

Related Questions