Swift核心数据谓词IN子句 [英] Swift Core Data Predicate IN Clause

查看:131
本文介绍了Swift核心数据谓词IN子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将IN子句与NSPredicate一起使用.我收到以下错误:

I'm attempting to use an IN clause with an NSPredicate. I'm getting the following error:

***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]:无法识别的选择器已发送至实例0xa000000000000611'

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 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()

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

Any ideas as to what the problem is?

推荐答案

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

You don't show how you are defining recentEmployeeIds, but assuming its something like

let recentEmployeeIds:[Int] = ...

然后您需要正确地初始化NSPredicate. argumentArray

then you need to init the NSPredicate correctly. There is no label for argumentArray

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

这篇关于Swift核心数据谓词IN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆