用于查找多对多关系与给定实体集匹配的实体的谓词

时间:2013-12-19 14:25:51

标签: objective-c macos cocoa core-data

我有一个实体Threadparticipants实体之间存在多对多关系Contact

如何获取Thread实体,该实体在其目的地具有完全相同的Contact实体作为NSSet我在其他地方收集的Contacts

这样的事情:

NSSet *participants = [NSSet setWithObjects:<Contact>, <Contact>, <Contact>];

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Thread", self.managedObjectContext];
[NSPredicate predicateWithFormat:@"self.participants == %@", participants];

fetchRequest.entity = entity;
fetchRequest.predicate = predicate;

1 个答案:

答案 0 :(得分:0)

您不能只比较像self.participants == %@", participants这样的谓词中的集合。这个谓词可能会更好:

[NSPredicate predicateWithFormat:
    @"ALL participants IN %@ && participants.count == %@", 
    participants, @(participants.count)];