[NSFetchedResultsController performFetch]中的错误

时间:2012-04-27 18:50:56

标签: ios core-data nsfetchedresultscontroller

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

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* - [NSFileManager fileSystemRepresentationWithPath:]:/ Users / ivanevf / Library / Application Support / iPhone Simulator / 5.1 /的转换失败应用程序/ 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;
}

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

P.S。我试过几件随机的东西: 1.从模拟器中删除app目录。 (/ Users / ivanevf / Library / Application Support / iPhone Simulator / 5.1 / Applications / 0EF75071-5C99-4181-8D4D-4437351EC1F4) 2.注释掉setPredicate,setSortDescriptors行方法调用

2 个答案:

答案 0 :(得分:1)

您似乎在cacheName中有一个额外的转义字符。尝试:

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

答案 1 :(得分:0)

我试试这个,     NSString * cacheName = [NSString stringWithFormat:@“%d%Conversation%d”,1,2]; 它扔掉了: 1onversation9283099

这是一个常规字符串,没什么奇怪的。