调用[self.fetchedResultsController performFetch]时出现以下错误。

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'*-[NSFileManager fileSystemRepresentationWithPath:]:/ Users / ivanevf / Library / Application Support / iPhone Simulator / 5.1 / Applications / 0EF75071-5C99-4181-8D4D- 4437351EC1F4 /库/缓存/.CoreDataCaches/SectionInfoCaches/0

这是初始化后我在控制器上进行的第一个调用。初始化看起来像这样:

- (NSFetchedResultsController *)fetchedResultsController
{
   if (_fetchedResultsController != nil) {
      return _fetchedResultsController;
 }

// Create and configure a fetch request with the Book entity.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Conversation" inManagedObjectContext:self.objectContext];
[fetchRequest setEntity:entity];

// Create the sort descriptors array.
NSSortDescriptor *msgAgeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"message" ascending:NO comparator:^NSComparisonResult(id obj1, id obj2) {
  // some code
}];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:msgAgeDescriptor, nil];

[fetchRequest setPredicate:[self fetchPredicate]];
[fetchRequest setSortDescriptors:sortDescriptors];
NSString *cacheName = [NSString stringWithFormat:@"%d%Conversation%d", self.viewType, self.location.bid];
// Create and initialize the fetch results controller.
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.objectContext sectionNameKeyPath:nil cacheName:cacheName];
_fetchedResultsController.delegate = self;

return _fetchedResultsController;
}


知道这里发生了什么吗?
谢谢!

ps。我尝试了一些随机的事情:
1.从模拟器中删除应用程序目录。 (/用户/ ivanevf /库/应用程序支持/ iPhone模拟器/5.1/Applications/0EF75071-5C99-4181-8D4D-4437351EC1F4)
2.注释掉setPredicate,setSortDescriptors行方法调用

最佳答案

看起来您在cacheName中有一个额外的转义字符。尝试:

NSString *cacheName = [NSString stringWithFormat:@"%dConversation%d",
                                                 self.viewType,
                                                 self.location.bid];

关于ios - [NSFetchedResultsController performFetch]中的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10356250/

10-09 02:21