【问题标题】:Error in [NSFetchedResultsController performFetch][NSFetchedResultsController performFetch] 中的错误
【发布时间】:2012-04-27 18:50:55
【问题描述】:

当我调用 [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;
}

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

附言我尝试了一些随机的事情: 1.从模拟器中删除app目录。 (/Users/ivanevf/Library/Application Support/iPhone Simulator/5.1/Applications/0EF75071-5C99-4181-8D4D-4437351EC1F4) 2.注释掉setPredicate、setSortDescriptors行方法调用

【问题讨论】:

    标签: ios core-data nsfetchedresultscontroller


    【解决方案1】:

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

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

    【讨论】:

    • 你是一个绅士和一个学者。我现在会羞愧地躲在角落里哭。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      相关资源
      最近更新 更多