核心数据匹配一个到许多关系到列表 [英] Core Data match a to many relationship to a list
本文介绍了核心数据匹配一个到许多关系到列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
相关于此问题,它发生了一个新的:
Related to this question, it occured a new one :
说我有这些属性: [red,green,blue]
fetch对象的某些或所有属性都在列表中但仅在此列表中
Say I have these Attributes : [red, green, blue]
How can I fetch objects whose some or all attributes are in list, but in this list only ?
* Object_1 (red, green, blue)
* Object_2 (red, green)
* Object_3 (red)
b $ b
这意味着不会获取 Object_4(红色,绿色,蓝色,黄色)
,因为它有黄色
不在列表中
This means not fetch Object_4 (red, green, blue, yellow)
because it has yellow
which is not in the list
推荐答案
您可以创建一个复合谓词,可以添加您的3个谓词:
you can make a compound predicate which can add your 3 predicates :
NSPredicate *predOne = [NSPredicate predicateWithFormat:@"color == %@",@"red"];
NSPredicate *predTwo = [NSPredicate predicateWithFormat:@"color == %@",@"blue"];
NSPredicate *predThree = [NSPredicate predicateWithFormat:@"color == %@",@"green"];
NSArray *allPredicates = [[NSArray alloc] initWithObjects:predOne,predTwo,predThree, nil];
NSPredicate finalPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:allPredicates];
这篇关于核心数据匹配一个到许多关系到列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文