我试图将IN子句与NSPredicate一起使用。我收到以下错误:
***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [NSTaggedPointerString countByEnumeratingWithState:objects:count:]:无法识别的选择器发送到实例0xa000000000000611'
以下是代码:
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()
关于问题是什么的任何想法?
答案 0 :(得分:7)
您没有展示如何定义recentEmployeeIds
,而是假设其类似
let recentEmployeeIds:[Int] = ...
然后你需要正确地初始化NSPredicate
。 argumentArray
fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", recentEmployeeIds)