我有一个Core Data应用程序,基本上可以用于检索数据,但是当我应用谓词时,没有过滤。换句话说,无论过滤器如何,都返回相同的结果。有什么建议?
lazy var frc: NSFetchedResultsController<Report> =
{
let context = self.app.persistentContainer.viewContext
let req: NSFetchRequest<Report> = Report.fetchRequest()
req.fetchBatchSize = 20
let sortDescriptor = NSSortDescriptor(key: "status", ascending:true)
req.sortDescriptors = [sortDescriptor]
let filter = self.app.currentFilter
//print(filter!)
let predicate = NSPredicate(format: "status == %@", filter)
req.predicate = predicate
let afrc = NSFetchedResultsController(fetchRequest: req, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: "reports")
afrc.delegate = self
do
{
try afrc.performFetch()
}
catch
{
fatalError("Abort while fetching report")
}
return afrc
}()
报告实体的状态属性为String
。
答案 0 :(得分:0)
根据上面的两条评论,答案可能在Apple documentation for NSFetchedResultsController。阅读修改获取请求部分,特别注意
您不能简单地更改获取请求以修改结果。