好的,我的fetch结果控制器出了问题。问题似乎是,当要求它从另一个表中提取数据时,异常发生在它似乎试图将一个表转换为另一个表的情况下。这是为什么?
var fetchedResultsController: NSFetchedResultsController<Task> {
if _fetchedResultsController != nil {
return _fetchedResultsController! as!
NSFetchedResultsController<Task>
}
let fetchRequest: NSFetchRequest<Task> = Task.fetchRequest()
// Set the batch size to a suitable number.
fetchRequest.fetchBatchSize = 20
// Edit the sort key as appropriate.
let sortDescriptor = NSSortDescriptor(key: "coursework", ascending:
true)
fetchRequest.sortDescriptors = [sortDescriptor]
let currentCoursework = self.detailItem
if(self.detailItem != nil){
let predicate = NSPredicate(format: "moduleCoursework", currentCoursework!)
fetchRequest.predicate = predicate
}
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
let aaFetchedResultsController =
NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext:
self.managedObjectContext,
sectionNameKeyPath:#keyPath(Coursework.modulename), cacheName: "Master")
aaFetchedResultsController.delegate = self
_fetchedResultsController = aaFetchedResultsController
do {
try _fetchedResultsController!.performFetch()
} catch {
/* Replace this implementation with code to handle the error
appropriately.
fatalError() causes the application to generate a crash log and
terminate. You should not use this function in a shipping application,
although it may be useful during development.*/
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
return _fetchedResultsController! as!
NSFetchedResultsController<Task>
}
var _fetchedResultsController: NSFetchedResultsController<Coursework>? =
nil