Jas*_*lin 16 core-data ios swift
我无法NSFetchedResultsController
在iOS 10中使用来自AECoreDataUI的CoreDataTableViewController中的 Swift 3进行初始化.
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)
Run Code Online (Sandbox Code Playgroud)
编译器抱怨说
"Cannot convert value of type NSFetchedResultsController<NasaPicture> to expected type NSFetchedResultsController<_>"
Run Code Online (Sandbox Code Playgroud)
控制器现在使用swift的泛型类型,但它没有正确地推断实体类型.我已经明确尝试过:
fetchedResultsController = NSFetchedResultsController<NasaPicture>(fetchRequest: request, managedObjectContext: moc, sectionNameKeyPath: nil, cacheName: nil)
Run Code Online (Sandbox Code Playgroud)
也没有运气.
谢谢!
Sul*_*han 24
NSFetchRequest
现在是通用的.NSFetchedResultsController
也是通用的.因此,在声明变量时,必须使用泛型声明,例如:
var fetchedResultsController: NSFetchedResultsController<NasaPicture>?
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10917 次 |
最近记录: |