NSPredicate使用数组作为过滤器 [英] NSPredicate use array as filter
本文介绍了NSPredicate使用数组作为过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用数组作为过滤器来搜索核心数据. fetchRequest返回的值应具有谓词数组中的ID.
I'm trying to use an array as a filter to search Core Data. The values that the fetchRequest returns should have an ID that is in the predicate's array.
let arrayOfFavoriteStampIDS = [302,2300,2309]
fetchRequest.predicate = NSPredicate(format: "itemID IN %i", argumentArray: arrayOfFavoriteStampIDS)
推荐答案
几乎
fetchRequest.predicate = NSPredicate(format: "itemID IN %@", arrayOfFavoriteStampIDS)
argumentArray
表示其他含义
fetchRequest.predicate = NSPredicate(format: "itemID == %i OR itemID == %i OR itemID == %i", argumentArray:arrayOfFavoriteStampIDS)
在这种情况下,数组中的每个项目都必须匹配一个%i
占位符.
In this case each item in the array must match one %i
placeholder.
这篇关于NSPredicate使用数组作为过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文