与这个问题相关,它出现了一个新问题:
假设我有这些属性:[red, green, blue]
如何获取其部分或全部属性在列表中但仅在此列表中的对象?
* Object_1 (red, green, blue)
* Object_2 (red, green)
* Object_3 (red)
这意味着不获取Object_4 (red, green, blue, yellow)
,因为它有yellow
不在列表中
与这个问题相关,它出现了一个新问题:
假设我有这些属性:[red, green, blue]
如何获取其部分或全部属性在列表中但仅在此列表中的对象?
* Object_1 (red, green, blue)
* Object_2 (red, green)
* Object_3 (red)
这意味着不获取Object_4 (red, green, blue, yellow)
,因为它有yellow
不在列表中
您可以制作一个复合谓词,它可以添加您的 3 个谓词:
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];