iOS Complex sectionNameKeyPath问题

时间:2013-10-15 02:33:03

标签: ios core-data nsfetchedresultscontroller

我正在尝试使用日期和类型创建NSFetchedResultsController。

我的数据如下:

{
 @"date", NSDate,
 @"type", NSString
}

这就是我的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]];
}

这是我的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];

我收到此错误:

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'";

谁能看到我在这里做错了什么?

0 个答案:

没有答案