1

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

* 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'* -[NSFileManager fileSystemRepresentationWithPath:]:/Users/ivanevf/Library/Application Support/iPhone Simulator/5.1/Applications/0EF75071-5C99-4181-8D4D- 的转换失败4437351EC1F4/Library/Caches/.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.从模拟器中删除应用程序目录。(/Users/ivanevf/Library/Application Support/iPhone Simulator/5.1/Applications/0EF75071-5C99-4181-8D4D-4437351EC1F4) 2.注释掉setPredicate,setSortDescriptors行方法调用

4

2 回答 2

1

看起来你在cacheName. 尝试:

NSString *cacheName = [NSString stringWithFormat:@"%dConversation%d",
                                                 self.viewType,
                                                 self.location.bid];
于 2012-04-27T20:13:38.900 回答
0

我试试这个, NSString *cacheName = [NSString stringWithFormat:@"%d%Conversation%d", 1, 2]; 它抛出:1onversation9283099

这是一个普通的字符串,没什么奇怪的。

于 2013-04-02T03:18:54.583 回答