我有一个符合协议FetchedResultsControlable
的类:
protocol FetchedResultsControlable {
var entityType: AnyClass
}
现在我需要创建 NSFRC :
class A: FetchedResultsControlable {
var entityType: AnyClass {
return Order.classForCoder()
}
func setupFetchedResultsController(delegate: NSFetchedResultsControllerDelegate) {
let fetchRequest = NSFetchRequest<entityType>(entityName: "\(entityType)")
let identifierDescriptor = NSSortDescriptor(key: "identifier", ascending: false)
fetchRequest.sortDescriptors = [identifierDescriptor]
fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: storage.context, sectionNameKeyPath: nil, cacheName: nil)
fetchedResultsController?.delegate = delegate
}
}
我需要使用通用类型创建frc,但这不起作用;) 如何使用泛型来实现该功能?