ios – 核心数据不支持带有ALL和IN的谓词

ios – 核心数据不支持带有ALL和IN的谓词,第1张

概述我有这样的请求: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY attributes.attribute.attributeId IN %@", attributeIds]; 这将返回一个对象列表,其中包含我设置的一个或多个属性.我想得到一个包含我通过的所有属性的对象列表,所以我尝试了: NSPredicate *p 我有这样的请求:

nspredicate *predicate = [nspredicate predicateWithFormat:@"ANY attributes.attribute.attributeID IN %@",attributeIDs];

这将返回一个对象列表,其中包含我设置的一个或多个属性.我想得到一个包含我通过的所有属性的对象列表,所以我尝试了:

nspredicate *predicate = [nspredicate predicateWithFormat:@"ALL attributes.attribute.attributeID IN %@",attributeIDs];

但我有一个例外:

'NSinvalidargumentexception',reason: 'Unsupported predicate (null)'

无论如何,我甚至不确定这是正确的要求.假设我有属性列表:[红色,绿色,蓝色],我如何获得至少具有这些属性的所有对象?

* Object_1 (red,green,blue)* Object_2 (red,blue,yellow,brown)* Object_3 (red,green blue,black,brown)

但不是Object_4(红色,黄色),因为它没有蓝色属性(请注意,我按照预期获取了所有4个带有我的任何获取请求的对象)

编辑,相关问题:如果我想完全匹配怎么办?那么对于[红色,蓝色]我只会得到Object_1?

编辑2:我设法回答了这两个问题,但是I have a new one

解决方法 获取列表中至少包含所有属性的所有对象

nspredicate *objectsThatContainsAtLeastAllAttributesInList =    [nspredicate predicateWithFormat:        @"SUBquery(attributes,$s,$s.attribute.attributeID IN %@).@count == %d",attributeIDs,[attributeIDs count]];

获取仅包含列表中属性的所有对象

nspredicate *objectsWhoseAttributesAreInList =    [nspredicate predicateWithFormat:        @"attributes.@count == %d AND SUBquery(attributes,$s.attributes.ID IN %@).@count == %d",[attributeIDs count],[attributeIDs count]];
总结

以上是内存溢出为你收集整理的ios – 核心数据不支持带有ALL和IN的谓词全部内容,希望文章能够帮你解决ios – 核心数据不支持带有ALL和IN的谓词所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1053317.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存