Categories
core-data ios ios10 swift

Cannot convert value of type ‘NSFetchRequest’ to specified type ‘NSFetchRequest’

I want to use new Core Data API introduced in iOS10.

@available(iOS 10.0, *)
open class func fetchRequest() -> NSFetchRequest<NSFetchRequestResult>

I created generic function to fetching all kinds of objects:

func getAllEntities<T: NSManagedObject>(ofType type: T.Type, success: @escaping ([T]) -> ()) throws -> [T] {
let fetchRequest: NSFetchRequest<T> = T.fetchRequest()
let asyncFetchRequest = NSAsynchronousFetchResult(fetchRequest: fetchRequest) { result in
success(result.finalResult ?? [])
}
try databaseStack.persistentContainer.viewContext.execute(asyncFetchRequest)
}

but in line let fetchRequest: NSFetchRequest<T> = T.fetchRequest() I got issue:

Cannot convert value of type 'NSFetchRequest<NSFetchRequestResult>' to specified type 'NSFetchRequest<T>'

What did I do wrong?