I am trying to create a NSFetchedResultsController using date and type.
My Data looks like this :
{
@"date", NSDate,
@"type", NSString
}
This is what my NSManagedObject
- (NSString*)dayTypeStringOnly {
NSCalendar *cal = [NSCalendar currentCalendar];
return [NSString stringWithFormat:@"%i%i%i%@", (int)[[cal components:NSYearCalendarUnit fromDate:self.startTime] year],(int)[[cal components:NSMonthCalendarUnit fromDate:self.startTime] month],(int)[[cal components:NSDayCalendarUnit fromDate:self.date] day], [self.type lowercaseString]];
}
Here is my NSFetchedResultsController:
NSFetchRequest *dataRequest = [NSFetchRequest fetchRequestWithEntityName:entityName];
[dataRequest setPredicate:kHiddenPredicate];
[dataRequest setFetchBatchSize:kMagicalRecordDefaultBatchSize];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"type" ascending:NO selector:@selector(caseInsensitiveCompare:)];
[dataRequest setSortDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES], sortDescriptor]];
NSFetchedResultsController *dataFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:dataRequest
managedObjectContext:[NSManagedObjectContext MR_defaultContext]
sectionNameKeyPath:@"dayTypeStringOnly"
cacheName:nil];
I am getting this error:
Unresolved error Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0x10e847230 {reason=The fetched object at index 8 has an out of order section name '20131011pump. Objects must be sorted by section name'}, {
reason = "The fetched object at index 8 has an out of order section name '20131011pump. Objects must be sorted by section name'";
Can anyone see what I am doing wrong here?