快速核心数据谓词IN条款

时间:2017-03-07 15:48:04

标签: ios swift core-data nspredicate

我试图将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()

关于问题是什么的任何想法?

1 个答案:

答案 0 :(得分:7)

您没有展示如何定义recentEmployeeIds,而是假设其类似

let recentEmployeeIds:[Int] = ...

然后你需要正确地初始化NSPredicateargumentArray

没有标签
fetchRequest.predicate = NSPredicate(format: "ANY id IN %@", recentEmployeeIds)