我无法NSFetchedResultsController使用AECoreDataUI的CoreDataTableViewController中的 Swift 3在iOS 10中进行初始化。
NSFetchedResultsController
let request = NSFetchRequest<NasaPicture>(entityName:"NasaPicture") request.predicate = Predicate(format: "isPagedResult == YES") request.sortDescriptors = [SortDescriptor(key: "date", ascending: false)] fetchedResultsController = NSFetchedResultsController(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil)
编译器抱怨
"Cannot convert value of type NSFetchedResultsController<NasaPicture> to expected type NSFetchedResultsController<_>"
控制器现在正使用通用类型进行快速处理,但未正确推断实体类型。我已经明确尝试过:
fetchedResultsController = NSFetchedResultsController<NasaPicture>(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil)
也没有运气。
谢谢!
NSFetchRequest现在是通用的。NSFetchedResultsController也是通用的。因此,在声明变量时,必须使用通用声明,例如:
NSFetchRequest
var fetchedResultsController: NSFetchedResultsController<NasaPicture>?