I've created a table view of "log entries" which are organized into section based on the day they were entered.
I'm using Core Data so in order to do this I defined the following readonly calculated property in my NSManagedObject:
- (NSString *)formattedDay {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setTimeStyle:NSDateFormatterNoStyle];
[df setDateFormat:@"EEEE MMMM d, YYYY"];
NSString *dateString = [df stringFromDate:self.timestamp];
[df release];
return dateString;
}
Then I use sectionNameKeyPath:@"formattedDay"
in my NSFetchedResultsController.
This works fine but is a bit inefficient because a string must be formatted for every log row. Is there a way I can just have this return an NSDate (instead of a string) then somehow access the NSDate in titleForHeaderInSection:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return sectionInfo.name;
}
Or somehow control how NSFetchedResultsController turns an NSDate into sectionInfo.name ?