[NSFetchedResultsController performFetch] 中的错误
Posted
技术标签:
【中文标题】[NSFetchedResultsController performFetch] 中的错误【英文标题】:Error in [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行方法调用
【问题讨论】:
【参考方案1】:看起来你在cacheName
中有一个额外的转义字符。试试:
NSString *cacheName = [NSString stringWithFormat:@"%dConversation%d",
self.viewType,
self.location.bid];
【讨论】:
你是一个绅士和一个学者。我现在会羞愧地躲在角落里哭。【参考方案2】:我试试这个, NSString *cacheName = [NSString stringWithFormat:@"%d%Conversation%d", 1, 2]; 它抛出: 1onversation9283099
这是一个普通的字符串,没什么奇怪的。
【讨论】:
以上是关于[NSFetchedResultsController performFetch] 中的错误的主要内容,如果未能解决你的问题,请参考以下文章
表更新时 NSFetchedResultsController 无法滚动
使用 UISegmentedControl 切换 NSFetchedResultsController
核心数据 - NSFetchedResultsController 错误
将 fetchedResultsController 与 swift3 一起使用
Core Data / NSManagedObject / NSFetchedResultsController 中的多属性“事务”?