我正在尝试使用带有NSPredicate的IN子句。我收到以下错误:



这是代码:

let fetchRequest: NSFetchRequest<Employee> = NSFetchRequest(entityName: "Employee")

fetchRequest.sortDescriptors = [
     NSSortDescriptor.init(key: "lastName", ascending: true)
]

fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", argumentArray: recentEmployeeIds)

fetchedResultsController = NSFetchedResultsController.init(fetchRequest: fetchRequest,
                                                                           managedObjectContext: FLCoreDataController.shared.mainObjectContext,
                                                                           sectionNameKeyPath: nil,
                                                                           cacheName: nil)
fetchedResultsController?.delegate = self

try? fetchedResultsController?.performFetch()

关于问题所在有什么想法吗?

最佳答案

您没有显示如何定义recentEmployeeIds,而是假设它类似于

let recentEmployeeIds:[Int] = ...

那么您需要正确初始化NSPredicate。没有argumentArray的标签
fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", recentEmployeeIds)

关于ios - Swift核心数据谓词IN子句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42652555/

10-13 03:50